我在填写3种表单输入时遇到问题。 单选按钮,选择(下拉列表)和textarea。
<textarea name="kommentar" cols="25" rows="7" value="<?php echo "$comment";?>" required></textarea> <select name="interesse" required> <option disabled selected>Bitte auswählen</option> <option>Java</option> <option>PHP</option> <option>C++</option> <option>Ruby</option> <option>SQL</option> <option>PLSQL</option> </select> <fieldset> <label for="bewertung"> <input type="radio" name="bewertung" value="1" required />1 <input type="radio" name="bewertung" value="2" required />2 <input type="radio" name="bewertung" value="3" required />3 <input type="radio" name="bewertung" value="4" required />4 <input type="radio" name="bewertung" value="5" required />5 <input type="radio" name="bewertung" value="6" required />6 </label> </fieldset>我需要一个预先选择的单选按钮,选择的下拉列表条目,还应填写注释字段(这还不起作用)。 怎么可能用php变量填充这些值?
I'm having issues with filling 3 types of form input. Radio buttons, select (drop-down list) and textarea.
<textarea name="kommentar" cols="25" rows="7" value="<?php echo "$comment";?>" required></textarea> <select name="interesse" required> <option disabled selected>Bitte auswählen</option> <option>Java</option> <option>PHP</option> <option>C++</option> <option>Ruby</option> <option>SQL</option> <option>PLSQL</option> </select> <fieldset> <label for="bewertung"> <input type="radio" name="bewertung" value="1" required />1 <input type="radio" name="bewertung" value="2" required />2 <input type="radio" name="bewertung" value="3" required />3 <input type="radio" name="bewertung" value="4" required />4 <input type="radio" name="bewertung" value="5" required />5 <input type="radio" name="bewertung" value="6" required />6 </label> </fieldset>I need a preselected radio button, selected drop-down list entry and also the comment field should be filled (that doesn't work yet). How is it possible, to fill these with values from php variables?
最满意答案
<textarea>不支持value属性,在<textarea></textarea>标记之间回显$comment 。
使用条件逻辑检查单选按钮并选择框选项:
<option value="bar" name="foobar" <?php echo ($foobar == "bar" ? "selected=\"selected\"" : ""); ?>>bar</option> <input type="radio" value="foo" name="foobar" <?php echo ($foobar == "foo" ? "checked=\"checked\"" : ""); ?> /> fooUPDATE
应用于您的原始代码:
<?php $interesse = "PHP"; $bewertung = 4; ?> <textarea name="kommentar" cols="25" rows="7" required><?php echo "$comment";?></textarea> <select name="interesse" required> <option disabled>Bitte auswählen</option> <option <?php echo ($interesse == "Java" ? "selected=\"selected\"" : ""); ?>>Java</option> <option <?php echo ($interesse == "PHP" ? "selected=\"selected\"" : ""); ?>>PHP</option> <option <?php echo ($interesse == "C++" ? "selected=\"selected\"" : ""); ?>>C++</option> <option <?php echo ($interesse == "Ruby" ? "selected=\"selected\"" : ""); ?>>Ruby</option> <option <?php echo ($interesse == "SQL" ? "selected=\"selected\"" : ""); ?>>SQL</option> <option <?php echo ($interesse == "PLSQL" ? "selected=\"selected\"" : ""); ?>>PLSQL</option> </select> <fieldset> <label for="bewertung"> <input type="radio" name="bewertung" value="1" required <?php echo ($bewertung == 1 ? "checked=\"checked\"" : ""); ?> />1 <input type="radio" name="bewertung" value="2" required <?php echo ($bewertung == 2 ? "checked=\"checked\"" : ""); ?> />2 <input type="radio" name="bewertung" value="3" required <?php echo ($bewertung == 3 ? "checked=\"checked\"" : ""); ?> />3 <input type="radio" name="bewertung" value="4" required <?php echo ($bewertung == 4 ? "checked=\"checked\"" : ""); ?> />4 <input type="radio" name="bewertung" value="5" required <?php echo ($bewertung == 5 ? "checked=\"checked\"" : ""); ?> />5 <input type="radio" name="bewertung" value="6" required <?php echo ($bewertung == 6 ? "checked=\"checked\"" : ""); ?> />6 </label> </fieldset>这将选择“PHP”选项并选中第4个单选按钮。
<textarea> doesn't support the value attribute, echo your $comment between the <textarea></textarea> tags.
Use conditional logic to check off a radio button and select box options:
<option value="bar" name="foobar" <?php echo ($foobar == "bar" ? "selected=\"selected\"" : ""); ?>>bar</option> <input type="radio" value="foo" name="foobar" <?php echo ($foobar == "foo" ? "checked=\"checked\"" : ""); ?> /> fooUPDATE
Applied to your original code:
<?php $interesse = "PHP"; $bewertung = 4; ?> <textarea name="kommentar" cols="25" rows="7" required><?php echo "$comment";?></textarea> <select name="interesse" required> <option disabled>Bitte auswählen</option> <option <?php echo ($interesse == "Java" ? "selected=\"selected\"" : ""); ?>>Java</option> <option <?php echo ($interesse == "PHP" ? "selected=\"selected\"" : ""); ?>>PHP</option> <option <?php echo ($interesse == "C++" ? "selected=\"selected\"" : ""); ?>>C++</option> <option <?php echo ($interesse == "Ruby" ? "selected=\"selected\"" : ""); ?>>Ruby</option> <option <?php echo ($interesse == "SQL" ? "selected=\"selected\"" : ""); ?>>SQL</option> <option <?php echo ($interesse == "PLSQL" ? "selected=\"selected\"" : ""); ?>>PLSQL</option> </select> <fieldset> <label for="bewertung"> <input type="radio" name="bewertung" value="1" required <?php echo ($bewertung == 1 ? "checked=\"checked\"" : ""); ?> />1 <input type="radio" name="bewertung" value="2" required <?php echo ($bewertung == 2 ? "checked=\"checked\"" : ""); ?> />2 <input type="radio" name="bewertung" value="3" required <?php echo ($bewertung == 3 ? "checked=\"checked\"" : ""); ?> />3 <input type="radio" name="bewertung" value="4" required <?php echo ($bewertung == 4 ? "checked=\"checked\"" : ""); ?> />4 <input type="radio" name="bewertung" value="5" required <?php echo ($bewertung == 5 ? "checked=\"checked\"" : ""); ?> />5 <input type="radio" name="bewertung" value="6" required <?php echo ($bewertung == 6 ? "checked=\"checked\"" : ""); ?> />6 </label> </fieldset>This would have the "PHP" option selected and the 4th radio button checked.
更多推荐
php,option>,drop-down,电脑培训,计算机培训,IT培训"/> <meta name="desc
发布评论