2010-10-13 113 views
2

我正在做一個簡單的註冊表單,並且無法獲得提交的選擇字段之一。我的HTML和PHP都驗證好,任何人都可以請幫忙嗎?我的PHP是這樣的:非常簡單的PHP表單 - 一個字段沒有提交

<?php 

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); 

// Checkbox handling 
$field_9_opts = $_POST['field_9'][0]; 

mail("[email protected]","A message from the Website","A message from the Website: 

Their name: " . $_POST['field_1'] . " 
Their email address: " . $_POST['field_2'] . " 
Their contact number: " . $_POST['field_3'] . " 
The customer would prefer to be contacted: " . $_POST['field_4'] . " 
The type of property the customer is interested in: " . $_POST['field_5'] . " 
Their price range: " . $_POST['field_6'] . " 
Their reason for purchase: " . $_POST['field_7'] . " 
They heard about Parkway Newbury from: " . $_POST['field_8'] . " 
Keep me updated on news on Parkway Living, Newbury: $field_9_opts 

"); 

include("confirm.html"); 

?> 

和我的HTML看起來像這樣:

<form method="post" enctype="multipart/form-data" action="processor.php"> 
<ul id="mainForm_1"> 

<li id="fieldBox_1"> 
<label>Your name&nbsp;*</label> 
<input type="text" name="field_1" id="field_1" size="20" value="" /> 
</li> 

<li id="fieldBox_2"> 
<label>Your email address&nbsp;*</label> 
<input type="text" name="field_2" id="field_2" size="20" value="" /> 
</li> 

<li id="fieldBox_3"> 
<label>Your contact number&nbsp;*</label> 
<input type="text" name="field_3" id="field_3" size="20" value="" /> 
</li> 

<li id="fieldBox_4"> 
<label>I would prefer to be contacted&nbsp;*</label> 
<select name="field_4" id="field_4"> 
    <option value="">Please select from the list</option> 
    <option value="In the morning">In the morning</option> 
    <option value="In the afternoon">In the afternoon</option> 
    <option value="In the evening">In the evening</option> 
    <option value="Anytime">Anytime</option> 
</select> 
</li> 

<li id="fieldBox_5"> 
<label>Property type&nbsp;*</label> 
<select name="field_5" id="field_5"> 
    <option value="">Please select from the list</option> 
    <option value="Duplex">Duplex</option> 
    <option value="Apartment">Apartment</option> 
    <option value="Both">Both</option> 
</select> 
</li> 

<li id="fieldBox_6"> 
<label>Prices from&nbsp;*</label> 
<select name="field_6" id="field_6"> 
    <option value="">Please select from the list</option> 
    <option value="upto &pound;200,000">upto &pound;200,000</option> 
    <option value="&pound;200,000 - &pound;300,000">&pound;200,000 - &pound;300,000</option> 
    <option value="&pound;300,000 - &pound;400,000">&pound;300,000 - &pound;400,000</option> 
    <option value="Above &pound;400,000">Above &pound;400,000</option> 
</select> 
</li> 

<li id="fieldBox_7"> 
<label>Reason for purchase&nbsp;*</label> 
<select name="field_7" id="field_7"> 
    <option value="">Please select from the list</option> 
    <option value="Moving into the area">Moving into the area</option> 
    <option value="First time buyer">First time buyer</option> 
    <option value="Downsizing">Downsizing</option> 
    <option value="Need more space">Need more space</option> 
</select> 
</li> 

<li id="fieldBox_8"> 
<label>Where did you hear about Parkway Living?&nbsp;*</label> 
<select name="field_8" id="field_8"> 
    <option value="">Please select from the list</option> 
    <option value="Website">Website</option> 
    <option value="National advertising">National Advertising</option> 
    <option value="Local advertising">Local Advertising</option> 
    <option value="Recommendation">Recommendation</option> 
    <option value="Selling agent">Selling agent</option> 
    <option value="Site visit">Site visit</option> 
    <option value="Other">Other</option> 
</select> 
</li> 

<li id="fieldBox_9"> 
<label>Keep me updated on news on Parkway Living, Newbury&nbsp;*</label> 
<span> 
    <input type="checkbox" name="field_9[]" id="field_9_option_1" value="yes" /> 
</span> 
</li> 

<li> 
<input id="saveForm" type="submit" value="Submit" /> 
</li> 
</ul> 
</form> 

不會被提交場8.我將不勝感激任何意見的領域。提前致謝。

+2

也許有助於獲得表單的代碼。 – Jake 2010-10-13 09:15:40

+0

你能顯示你的html嗎? – pltvs 2010-10-13 09:17:55

+0

@Jake,@Alexander我修改了我的文章以包含HTML - 謝謝 – mtwallet 2010-10-13 09:21:14

回答

1

你選擇的名稱應該是field_8[]

+1

不,你只需要,如果你想允許多個選擇。 – poke 2010-10-13 09:32:56

+1

僅當需要處理多項選擇時,[] - 後綴纔是必需的。 //被14秒的打擊>< – anddoutoi 2010-10-13 09:33:10

+0

@poke正確的是,不需要使用[],它用於將多個值作爲數組傳遞。 – 2010-10-13 09:41:01

2

我複製並在一個簡單的模板粘貼您的HTML和它的作品就像一個魅力。當然你複製並粘貼它是正確的?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html lang="sv"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
     <title></title> 
    </head> 
    <body> 
<?php 

if (!empty($_POST)) 
{ 
    echo '<pre>'; 
    print_r($_POST); 
    echo '</pre>'; 
} 

?> 
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
<ul id="mainForm_1"> 

<li id="fieldBox_1"> 
<label>Your name&nbsp;*</label> 
<input type="text" name="field_1" id="field_1" size="20" value="" /> 
</li> 

<li id="fieldBox_2"> 
<label>Your email address&nbsp;*</label> 
<input type="text" name="field_2" id="field_2" size="20" value="" /> 
</li> 

<li id="fieldBox_3"> 
<label>Your contact number&nbsp;*</label> 
<input type="text" name="field_3" id="field_3" size="20" value="" /> 
</li> 

<li id="fieldBox_4"> 
<label>I would prefer to be contacted&nbsp;*</label> 
<select name="field_4" id="field_4"> 
    <option value="">Please select from the list</option> 
    <option value="In the morning">In the morning</option> 
    <option value="In the afternoon">In the afternoon</option> 
    <option value="In the evening">In the evening</option> 
    <option value="Anytime">Anytime</option> 
</select> 
</li> 

<li id="fieldBox_5"> 
<label>Property type&nbsp;*</label> 
<select name="field_5" id="field_5"> 
    <option value="">Please select from the list</option> 
    <option value="Duplex">Duplex</option> 
    <option value="Apartment">Apartment</option> 
    <option value="Both">Both</option> 
</select> 
</li> 

<li id="fieldBox_6"> 
<label>Prices from&nbsp;*</label> 
<select name="field_6" id="field_6"> 
    <option value="">Please select from the list</option> 
    <option value="upto &pound;200,000">upto &pound;200,000</option> 
    <option value="&pound;200,000 - &pound;300,000">&pound;200,000 - &pound;300,000</option> 
    <option value="&pound;300,000 - &pound;400,000">&pound;300,000 - &pound;400,000</option> 
    <option value="Above &pound;400,000">Above &pound;400,000</option> 
</select> 
</li> 

<li id="fieldBox_7"> 
<label>Reason for purchase&nbsp;*</label> 
<select name="field_7" id="field_7"> 
    <option value="">Please select from the list</option> 
    <option value="Moving into the area">Moving into the area</option> 
    <option value="First time buyer">First time buyer</option> 
    <option value="Downsizing">Downsizing</option> 
    <option value="Need more space">Need more space</option> 
</select> 
</li> 

<li id="fieldBox_8"> 
<label>Where did you hear about Parkway Living?&nbsp;*</label> 
<select name="field_8" id="field_8"> 
    <option value="">Please select from the list</option> 
    <option value="Website">Website</option> 
    <option value="National advertising">National Advertising</option> 
    <option value="Local advertising">Local Advertising</option> 
    <option value="Recommendation">Recommendation</option> 
    <option value="Selling agent">Selling agent</option> 
    <option value="Site visit">Site visit</option> 
    <option value="Other">Other</option> 
</select> 
</li> 

<li id="fieldBox_9"> 
<label>Keep me updated on news on Parkway Living, Newbury&nbsp;*</label> 
<span> 
    <input type="checkbox" name="field_9[]" id="field_9_option_1" value="yes" /> 
</span> 
</li> 

<li> 
<input id="saveForm" type="submit" value="Submit" /> 
</li> 
</ul> 
</form> 
    </body> 
</html> 

選擇2個值(網站)生成的輸出:

Array 
(
    [field_1] => 
    [field_2] => 
    [field_3] => 
    [field_4] => 
    [field_5] => 
    [field_6] => 
    [field_7] => 
    [field_8] => Website 
) 

所以它的工作原理。

+0

如果我運行這個代碼,你在這裏粘貼一切似乎都提交罰款,除了field_9不應該[],但明確地使用作爲其他人。 – 2010-10-13 09:43:29

+0

感謝您的幫助,我很感激! – mtwallet 2010-10-13 09:45:59