2015-02-06 60 views
0

即時通訊嘗試在文本框,文本區域,單選按鈕組,複選框組和下拉列表中創建一個粘性窗體。我設法讓粘性部分與文本框一起工作,但對於其他所有內容,它不是保存在重新加載上,就是不在特定元素之後顯示內容。例如,我的代碼如下,在Male單選按鈕後沒有任何顯示。只是文字「男」,但沒有任何後。林不知道我做錯了什麼,我不知道如何使剩餘元素粘滯(文本區域,複選框和單選按鈕)。創建一個PHP的粘滯形式

<?php 
function display_form() 
{ 
    $self = $_SERVER['PHP_SELF']; 
    global $nameErr,$emailErr,$subjectErr,$commentErr,$termErr; 
    $name = isset($_POST['name']) ? $_POST['name'] : ''; 
    $email = isset($_POST['email']) ? $_POST['email'] : ''; 
    $subject = isset($_POST['subject']) ? $_POST['subject'] : ''; 
    $comment = isset($_POST['comment']) ? $_POST['comment'] : ''; 
?> 
<!doctype html> 
<html> 
<head> 
    <style> 
     .error {color: #FF0000;} 
    </style> 
</head> 
<body> 
<h1>Contact Us</h1> 
<form action="<?php echo $self ?>" method="POST"> 
    <span class="error"> <?php echo "* Required Field(s)";?></span> 
    <br><br> 
     Name: <input type="text" name="name" value="<?php echo $name?>"> 
    <span class="error">* <?php echo $nameErr;?></span> 
     <br><br> 
     E-Mail: <input type="text" name="email" value="<?php echo $email?>"> 
    <span class="error">* <?php echo $emailErr;?></span> 
     <br><br> 
     Gender: Male <input type="radio" <?php if($gender==="Male") echo "selected='selected'"; ?> name="gender" value="Male"> 
     Female <input type="radio" <?php if($gender==="Female") echo "selected='selected'"; ?> name="gender" value="Female"> 

     <br><br> 
     Subject: <select name="subject"> 
     <option value="select">Select...</option> 
      <option value="useraccount">User Account</option> 
      <option value="reportabuse">Report Abuse</option> 
      <option value="reporterror">Report Error</option> 
      <option value="jobs">Jobs</option> 
      <option value="other">Other</option> 
     </select> 
    <span class="error">* <?php echo $subjectErr;?></span> 
     <br><br> 
     Comment: <textarea name="comment" rows="5" cols="40"></textarea> 
    <span class="error">* <?php echo $commentErr;?></span> 
     <br><br> 
     <input type="checkbox" name="check_list[]" value="terms"><label>I understand the <a href="">Terms and Policies</a></label> 
    <span class="error">* <?php echo $termErr;?></span> 
    <br>     
     <input type="checkbox" name="check_list[]" value="subscribe"><label>Subscribe to our Monthly Newsletters</label> 
     <br><br> 
    <input type="submit" name="button" value="Submit"> 
    </form> 

</body> 
</html> 
<?php 
} 
?> 
+0

什麼檢查($性別 「男」),做更換的複選框? – 2015-02-06 05:37:33

+0

從什麼搜索,它應該選擇男性,如果它是以前選擇。所以基本上,使單選按鈕粘滯 – ShadowViper 2015-02-06 05:42:03

+0

我不這麼認爲,所以有任何內置的功能,像在PHP ..你需要寫一些登錄來做到這一點..刪除檢查功能,並嘗試看看它是否已解決或不。 – 2015-02-06 05:45:05

回答

0

與此代碼

Gender: Male <input type="radio" name="gender" <?php if($gender=="Male") echo"checked='checked'";?>value="Male"> 
Female <input type="radio" name="gender" <?php if($gender=="Female") echo"checked='checked'";?> value="Female"> 
+0

不幸的是,它仍然不能正常工作 – ShadowViper 2015-02-06 06:16:18

+0

我測試了它兄弟,讓我們聊聊吧! – 2015-02-06 06:20:46