表单错误消息无法正常工作,表单不会提交 [英] Form error messages not working properly, form wont submit
问题描述
<?php
$ myemail =ysjostar072@gmail.com;
$ name = check_input($ _ POST ['name'],输入你的名字);
$ company = check_input($ _ POST ['company'],输入您的公司名称);
$ function = check_input($ _ POST ['function'],提供场合);
$ address = check_input($ _ POST ['address'],输入你的地址);
$ place = check_input($ _ POST ['place'],输入您的区号);
$ number = check_input($ _ POST ['number'],输入你的号码);
$ mobile = check_input($ _ POST ['mobile'],输入您的手机号码);
$ email = check_input($ _ POST ['email'],输入有效的电子邮件地址);
$ client = check_input($ _ POST ['client'],你是客户吗?请让我们知道);
$ method = check_input($ _ POST ['method'],选择您喜欢的联系方式);
$ message = check_input($ _ POST ['message'],输入您的评论或描述);
$ date = check_input($ _ POST ['date'],告诉我们您的活动何时发生);
$ size = check_input($ _ POST ['size'],告诉我们你的演示文稿将会有多大);
$ subject =网站客户;
$ subject = striplashes($ subject);
if(isset($ _ POST ['button-submit'])){
if(!isset($ _ REQUEST ['email'])){
header(Location:index.html);
}
else {
mail(ysjostar072@gmail.com,反馈表单结果,
$ message,From:$ email);
header(Location:thanks.html);
}
}
如果(!preg_match(/([\w\ - ] + \ @ [\w\-] + \。[\w\ - ] +)/,$ email))
{
show_error(电子邮件地址无效);
}
$ inquiry =您好!
您的联系表单已提交:
名称:$名称
公司:$ company
事件:$ function
地址:$ address
地点:$ place
电子邮件:$ email
联系电话: $ number
手机:$ mobile
当前客户:$客户
评论:$ message
我的展览是$ date
尺寸:$ size
请联系我$方法
消息结束;
mail($ myemail,$ subject,$ inquiry);
header('Location:thanks.html');
exit();
函数check_input($ data,$ problem ='')
{
$ data = trim($ data);
$ data = stripslashes($ data);
$ data = htmlspecialchars($ data);
if($ problem&& strlen($ data)== 0)
{
show_error($ problem);
}
return $ data;
}
函数show_error($ myError)
{
?>
< html>
< body>
< b>请更正以下错误:< / b>< br />
<?php echo $ myError; ?>
< / body>
< / html>
<?php
exit();
}
?>
请帮助我。我不知道我做错了什么感谢提前:)
以下是HTML表单:
< form id =contactmethod =postaction =sendmail.phpenctype =multipart / form-data>
< ul>
< li style =margin-bottom:15px; text-align:left>< label for =name> Vorname / Name *< / label>
< input id =namename =Nametype =textvalue =class =name-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =company> Firma *< / label>
< input id =companyname =Companytype =textvalue =class =company-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =function> Funktion *< / label>
< input id =functionname =Functiontype =textvalue =class =function-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =address> Adresse *< / label>
< input id =addressname =Addresstype =textvalue =class =address-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =place> PLZ / Ort *< / label>
< input id =placename =Placetype =textvalue =class =place-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =number> Telefon *< / label>
< input id =numbername =Numbertype =textvalue =class =number-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =mobile> Mobiltelefon *< / label>
< input id =mobilename =Mobiletype =textvalue =class =mobile-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =email> E-Mail *< / label>
< input id =emailname =Emailtype =textvalue =class =email-field/>< / li>
< li style =margin-bottom:15px; text-align:left> Wir sind bereits Kunde *
< ; input type =radioname =Clientid =r1value =Ja/>
< label for =r1> Ja< / label>
< input type =radioname =Clientid =r2value =Nein/>
< label for =r2> Nein< / label>
< / li>
< li style =margin-bottom:15px; text-align:left> Kontaktieren Sie uns *
< input type = radioname =methodid =r3value =per telefon/>
< label for =r3>每个电话< / label>
< input type =radioname =methodid =r4value =Per e-mail/>
< label for =r4>每个电子邮件< / label>
< / li>
< li style =margin-bottom:15px; text-align:left>< label for =message> Bemerkungen *< / label>
< textarea id =messagename =Messagetype =textvalue =class =message-field>< / textarea>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =date>NächsteMesse datum *< / label>
< input id =datename =Datetype =textvalue =class =date-field/>< / li>
< li style =margin-bottom:15px; text-align:left>< label for =size>Standgrössem sq *< / label>
< input id =sizename =Sizetype =textvalue =class =size-field/>< / li>
< li style =margin-top:25px; margin-right:10px; text-align:left; color:#F00> * Diese Felder werdenbenötigt< / li>
< input type =submitclass =button-submitid =button-submitvalue =Sendenname =button-submit/>
< / ul>
< / form>
我尝试过这个代码,侧!尝试utf8编码您的文本,表单输入名称等...
< input type ='text'name = '名称' >
<?php
$ myemail =tresorunikin@gmail.com;
$ name = check_input($ _ POST ['name'],输入你的名字);
$ company = check_input($ _ POST ['company'],输入您的公司名称);
$ function = check_input($ _ POST ['function'],提供场合);
$ address = check_input($ _ POST ['address'],输入你的地址);
$ place = check_input($ _ POST ['place'],输入您的区号);
$ number = check_input($ _ POST ['number'],输入你的号码);
$ mobile = check_input($ _ POST ['mobile'],输入您的手机号码);
$ email = check_input($ _ POST ['email'],输入有效的电子邮件地址);
$ client = check_input($ _ POST ['client'],你是客户吗?请让我们知道);
$ method = check_input($ _ POST ['method'],选择您喜欢的联系方式);
$ message = check_input($ _ POST ['message'],输入您的评论或描述);
$ date = check_input($ _ POST ['date'],告诉我们您的活动何时发生);
$ size = check_input($ _ POST ['size'],告诉我们你的演示文稿将会有多大);
$ subject =网站客户;
$ subject = striplashes($ subject);
if(isset($ _ POST ['button-submit'])){
if(!isset($ _ REQUEST ['email'])){
header(Location:index.html);
}
else {
mail(ysjostar072@gmail.com,反馈表单结果,
$ message,From:$ email);
header(Location:thanks.html);
}
}
如果(!preg_match(/([\w\ - ] + \ @ [\w\-] + \。[\w\ - ] +)/,$ email))
{
show_error(电子邮件地址无效);
}
$ inquiry =您好!
您的联系表单已提交:
名称:$名称
公司:$ company
事件:$ function
地址:$ address
地点:$ place
电子邮件:$ email
联系电话: $ number
手机:$ mobile
当前客户:$客户
评论:$ message
我的展览是$ date
尺寸:$ size
请联系我$方法
消息结束;
mail($ myemail,$ subject,$ inquiry);
header('Location:thanks.html');
exit();
函数check_input($ data,$ problem ='')
{
$ data = trim($ data);
if(strlen($ data)== 0)
{
show_error($ problem);
}
$ data = stripslashes($ data);
$ data = htmlspecialchars($ data);
返回$数据;
}
函数show_error($ myError)
{
?>
< html>
< body>
< b>请更正以下错误:< / b>< br />
<?php echo $ myError; ?>
< / body>
< / html>
<?php
exit();
}
?>
I'm pretty new to form validation and processing, in fact, this is my first attempt, and I've created a simple contact form with required text fields, comments text area and two radio buttons. I've gone through many basic tuts and have put together script using PHP. The problem I have is that when i click submit if the form is unfilled, I am directed to a new page that has an error message saying i need to fill in my name. But if I fill in my name and click submit, I get the same message instead of the error message specified for the next field. I even get that message when all fields are filed in. Here is my code:
<?php
$myemail = "ysjostar072@gmail.com";
$name = check_input($_POST['name'], "Enter your name");
$company = check_input($_POST['company'], "Enter your company name");
$function = check_input($_POST['function'], "Provide an occassion");
$address = check_input($_POST['address'], "Enter your address");
$place = check_input($_POST['place'], "Enter your area code");
$number = check_input($_POST['number'], "Enter your number");
$mobile = check_input($_POST['mobile'], "Enter your mobile number");
$email = check_input($_POST['email'], "Enter a valid E-Mail address");
$client = check_input($_POST['client'], "Are you a client already? Please let us know");
$method = check_input($_POST['method'], "Choose your preferred method of contact");
$message = check_input($_POST['message'], "Enter your comments or description");
$date = check_input($_POST['date'], "Tell us when your event takes place");
$size = check_input($_POST['size'], "Tell us how big your presentation is going to be");
$subject = "Client from website";
$subject = striplashes($subject);
if(isset($_POST['button-submit'])) {
if (!isset($_REQUEST['email'])) {
header( "Location: index.html" );
}
else {
mail( "ysjostar072@gmail.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: thanks.html" );
}
}
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$enquiry = "Hello!
Your contact form has been submitted by:
Name: $name
Company: $company
Event: $function
Address: $address
Place: $place
E-mail: $email
Contact number: $number
Mobile: $mobile
Current client: $Client
Comments: $message
My exhibition is on $date
Size: $size
Please contact me $method
End of message";
mail($myemail, $subject, $enquiry);
header('Location: thanks.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
Please help me out. I don't know what I'm doing wrong. Thanks in advance :)
Here is the HTML form:
<form id="contact" method="post" action="sendmail.php" enctype="multipart/form-data">
<ul>
<li style="margin-bottom:15px; text-align:left"><label for="name">Vorname/Name*</label>
<input id="name" name="Name" type="text" value="" class="name-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="company">Firma*</label>
<input id="company" name="Company" type="text" value="" class="company-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="function">Funktion*</label>
<input id="function" name="Function" type="text" value="" class="function-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="address">Adresse*</label>
<input id="address" name="Address" type="text" value="" class="address-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="place">PLZ/Ort*</label>
<input id="place" name="Place" type="text" value="" class="place-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="number">Telefon*</label>
<input id="number" name="Number" type="text" value="" class="number-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="mobile">Mobiltelefon*</label>
<input id="mobile" name="Mobile" type="text" value="" class="mobile-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="email">E-Mail*</label>
<input id="email" name="Email" type="text" value="" class="email-field" /></li>
<li style="margin-bottom:15px; text-align:left">Wir sind bereits Kunde*
<input type="radio" name="Client" id="r1" value="Ja" />
<label for="r1">Ja</label>
<input type="radio" name="Client" id="r2" value="Nein" />
<label for="r2">Nein</label>
</li>
<li style="margin-bottom:15px; text-align:left">Kontaktieren Sie uns*
<input type="radio" name="method" id="r3" value="Per telefon" />
<label for="r3">Per telefon</label>
<input type="radio" name="method" id="r4" value="Per e-mail" />
<label for="r4">Per e-mail</label>
</li>
<li style="margin-bottom:15px; text-align:left"><label for="message">Bemerkungen*</label>
<textarea id="message" name="Message" type="text" value="" class="message-field" ></textarea></li>
<li style="margin-bottom:15px; text-align:left"><label for="date">Nächste Messe datum*</label>
<input id="date" name="Date" type="text" value="" class="date-field" /></li>
<li style="margin-bottom:15px; text-align:left"><label for="size">Standgrösse m sq*</label>
<input id="size" name="Size" type="text" value="" class="size-field" /></li>
<li style="margin-top:25px; margin-right:10px; text-align:left; color:#F00">*Diese Felder werden benötigt.</li>
<input type="submit" class="button-submit" id="button-submit" value="Senden" name="button-submit" />
</ul>
</form>
I've tried this code and it works on my side! try to utf8 encode your text, the form inputs name and so on...
<input type='text' name='name'>
<?php
$myemail = "tresorunikin@gmail.com";
$name = check_input($_POST['name'], "Enter your name");
$company = check_input($_POST['company'], "Enter your company name");
$function = check_input($_POST['function'], "Provide an occassion");
$address = check_input($_POST['address'], "Enter your address");
$place = check_input($_POST['place'], "Enter your area code");
$number = check_input($_POST['number'], "Enter your number");
$mobile = check_input($_POST['mobile'], "Enter your mobile number");
$email = check_input($_POST['email'], "Enter a valid E-Mail address");
$client = check_input($_POST['client'], "Are you a client already? Please let us know");
$method = check_input($_POST['method'], "Choose your preferred method of contact");
$message = check_input($_POST['message'], "Enter your comments or description");
$date = check_input($_POST['date'], "Tell us when your event takes place");
$size = check_input($_POST['size'], "Tell us how big your presentation is going to be");
$subject = "Client from website";
$subject = striplashes($subject);
if(isset($_POST['button-submit'])) {
if (!isset($_REQUEST['email'])) {
header( "Location: index.html" );
}
else {
mail( "ysjostar072@gmail.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: thanks.html" );
}
}
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$enquiry = "Hello!
Your contact form has been submitted by:
Name: $name
Company: $company
Event: $function
Address: $address
Place: $place
E-mail: $email
Contact number: $number
Mobile: $mobile
Current client: $Client
Comments: $message
My exhibition is on $date
Size: $size
Please contact me $method
End of message";
mail($myemail, $subject, $enquiry);
header('Location: thanks.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
if (strlen($data) == 0)
{
show_error($problem);
}
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
这篇关于表单错误消息无法正常工作,表单不会提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!