[英]HTML Form + PHP Issues
I have looked everywhere and searched high and low. 我四处张望,搜寻高低。 I have seen many issues with the PHP code I'm about to post, but nothing pertaining to my specific issue I am seeing.
我已经看到许多与我将要发布的PHP代码有关的问题,但是与我看到的特定问题无关。
Here is my issue - The two lines ($values/$required) where I have 'name','email',subject','message' 这是我的问题-我有'name','email',subject','message'的两行($ values / $ required)
I would like to add 'tel' to it. 我想在其中添加“ tel”。 (ie 'name','email','tel','subject','message')
(即“姓名”,“电子邮件”,“电话”,“主题”,“消息”)
If I add it to one of the two lines (doesn't matter which one), I can still submit the form but it doesn't give me that line (telephone) in the email I receive. 如果我将其添加到两行之一(与哪一条无关),我仍然可以提交表单,但是在收到的电子邮件中却没有给我该行(电话)。
If I add the 'tel' to BOTH lines ($values/$required) then I get a "Please fill in all required fields, marked with *" when I hit submit (with all the lines filled out). 如果我将“ tel”添加到两行($ values / $ required)中,那么当我点击Submit(所有行均已填写)时,我将得到“请填写所有必填字段,并标有*”。
Can someone tell me what I am missing? 有人可以告诉我我想念什么吗?
Also - 'subject' is actually a vin/body # but if I change the label in the html to 'vin' instead of 'subject' then it gives me the "Please fill in all required fields, marked with *" error so I just left it as 'subject' even though that is not what is really associated with that line item in the form. 另外-'subject'实际上是一个vin / body#,但是如果我将html中的标签更改为'vin'而不是'subject',那么它会给我“请填写所有必填字段,并标有*”错误,因此我只是将其保留为“主题”,即使这与表单中的该订单项没有真正的关联。
<?php
if(!$_POST) exit;
$email = $_POST['email'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) {
echo $error;
} else {
$values = array('name','email','subject','message',);
$required = array('name','email','subject','message',);
$your_email = "myemail@mydomain.com";
$email_subject = "VIN / Body - ".$_POST['subject'];
$email_content = "PART INQUIRY INFORMATION BELOW \n";
foreach ($values as $key => $value) {
if (in_array($value,$required)) {
if ($key != 'subject' && $key != 'company') {
if (empty($_POST[$value])) {
echo 'Please fill in all required fields, marked with *';
exit;
}
}
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
Updated answer: 更新的答案:
Well, there's good news and bad news. 好吧,有好消息也有坏消息。 The good news is, I think your code is actually operating properly.
好消息是,我认为您的代码实际上正在正常运行。 I think that your form is not actually posting the 'tel' field.
我认为您的表格实际上并未发布“ tel”字段。
I tested by replacing the $_POST array with: 我通过将$ _POST数组替换为:
$_POST = array('name' => 'Joel', 'email' => 'joel.small@biscon.com.au', 'subject' => 'Guy','message' =>'Thingo','tel' => 'Some number');
I then added 'tel' to the 'values' array and your code worked as expected. 然后,我将“ tel”添加到“ values”数组中,并且您的代码按预期工作。
Do a print_r($_POST) before you process the data and look at the structure of the array. 在处理数据并查看数组的结构之前,请执行print_r($ _ POST)。 If the tel field isn't there, your form isn't submitting it.
如果tel字段不存在,则您的表单未提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.