我知道這個問題已經被問了很多,所以我跟着回覆,但錯誤仍然存在。未定義的索引錯誤PHP
這裏的錯誤:
Notice: Undefined index: cf_name in C:\wamp\www\Mentalist Magician\contact.php on line 3
Notice: Undefined index: cf_email in C:\wamp\www\Mentalist Magician\contact.php on line 4
等。
這裏是我的代碼:
<?php
$field_cf_name = $_POST['cf_name']; $field_cf_email =
$_POST['cf_email']; $field_cf_message = $_POST['cf_message'];
$field_cf_client = $_POST['cf_client'];
if(isset($_POST['cf_name'])){ $field_cf_name = $_POST['cf_name']; }
if(isset($_POST['cf_email'])){ $field_cf_email = $_POST['cf_email']; }
if(isset($_POST['cf_message'])){ $field_cf_message =
$_POST['cf_message']; } if(isset($_POST['cf_client'])){
$field_cf_client = $_POST['cf_client']; }
if (empty($field_cf_name) && empty($field_cf_email) &&
empty($field_cf_cellphone) && empty($field_cf_message)) {
echo 'Please fill in all required fields';
return false; }
else{ //process the rest of the form }
if($field_cf_client != ''){
echo "Submission Sent - Thank you!"; return false; }
else{ //process the rest of the form }
$mail_to = '[email protected]';
$subject = 'New Message From Client'; $headers = "From: " .
strip_tags($field_email) . "\r\n"; $headers .= "Reply-To: ".
strip_tags($field_email) . "\r\n"; $headers .= "MIME-Version:
1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body_message = '<html><body style="font-family:calibri,sans-serif;
font-size:18px">'; $body_message .= '<h2 style="font-weight:600;
font-size:27px; border-bottom:solid 1px #CCC;
padding-bottom:10px;">New Message From Your Website</h2>';
$body_message .= '<p><strong style="color:#000; font-weight:600;
">Client Name:</strong> '.$field_cf_name."</p>\n"."\n"; $body_message
.= '<p><strong style="color:#000; font-weight:600; ">Email:</strong>
'.$field_cf_email."</p>\n"."\n"; $body_message .= '<p><strong
style="color:#000; font-weight:600; ">Message:</strong>
'.$field_cf_message."</p>\n"."\n";
$body_message .= '</body></html>';
$mail_status = mail($mail_to, $subject, $body_message, $headers); ?>
表格代號:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" data-validate="parsley">
<label>Name</label><span class="red">*</span><br/>
<input name="cf_name" type="text" data-required="true" class="form-text2" />
<br/><br/><label>Email Address</label><span class="red">*</span><br/>
<input name="cf_email" type="text" data-required="true" data-type="email" class="form-text2" />
<br/><br/><label>Message</label><span class="red">*</span><br/>
<textarea name="cf_message" data-required="true" cols="" rows="" class="form-msg"></textarea>
<!-- Client Website -->
<input id="client" class="taken" name="cf_client" type="text" />
<!-- END -->
<p><input name="Submit" class="submit2" value="Submit" type="submit" /> echo "<div id="submitmessage">Message Sent!</div>"</p> </form>
有什麼建議?謝謝!
你能發表你的表格代碼嗎? – Lesleh
這個腳本是如何使用的?它是在另一個頁面上的表單中用作操作的頁面,還是嵌入在此頁面中的此表單? – Bram
對不起,我現在會發布我的表單代碼! – user2382274