为什么php不能用于我的表单? [英] Why does the php not work for my form?

查看:101
本文介绍了为什么php不能用于我的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发送电子邮件给我公司之前,我一直试图使此表格生效。它不会验证表单,只要有人点击提交就会发送。没有验证发生,我不知道该怎么做。



以下是一些表格

 < tr> 
< td>< label for =reason3>离开的原因?< / label>< / td>
< td>< input type =textid =reason3name =reason3class =c3>< / td>
< / tr>
< tr>
< td colspan =2>
< hr size =1.5color =#000000noshade>< / td>
< / tr>
< tr>
< td>< label for =maywe>我们可以联系上面列出的雇主吗?< br>
如果不是,请指出您不希望我们联系:< / label>< / td>
< td>< input type =textid =maywename =mayweclass =c3>< / td>
< / tr>
< tr>
< td>< label for =additional>您希望我们添加的任何附加信息< br>
在审核您的申请时需要考虑?< / label>< / td>
< td>< input type =textid =additionalname =additionalclass =c3>< / td>
< / tr>
< tr>
< td colspan =2>
< hr size =1.5color =#000000noshade>< / td>
< / tr>
< tr>
< td colspan =2>
< div class =c2>
< hr size =1.5color =#000000noshade>
以上信息真实完整,据我所知。我应该成为< br>由< a href =http://www.creativeurethanes.com/>雇用的
> Creative Urethanes,Inc。,< / a>对这个应用程序的任何虚假陈述可能是< br>
被认为是解雇的充分理由。< br>
我了解填写此应用程式并不表示有必要提供任何< br>
空缺职位,也不以任何方式强制本公司承担责任。< br>
我承认我已阅读Creative Urethanes的< a href =Memo.html>知识权利备忘< / a> ;. < input type =checkboxname =Yesvalue =Yes>< span class =c1>< sup>< i>< / i>< / sup><< ; /跨度><峰; br>
< br>< / div>
< / td>
< / tr>
< tr>
< td colspan =2>
< hr size =1.5color =#000000noshade>< / td>
< / tr>
< tr>
< td colspan =2>用您的全名和SSN以电子方式进行签名。< / td>
< / tr>
< tr>
< td>< label for =electronicsignfn>< u>完整< / u> < u>< />< / span>< / label>< / TD>
< td>< input type =textid =electronicsignfnname =electonicsignfnclass =c3>< / td>
< / tr>
< tr>
< td>< label for =electronicsignssn>< u>< u> SSN< / span>< I>< / SUP>< /跨度>< /标签>< / TD>
< td>< input type =textid =electronicsignssnname =electronicsignssnclass =c3>< / td>
< / tr>
< tr>
< td>< label for =emailaddress>< u>电子邮件< / u> < u>地址< />< span class =c1>< sup>< i>< / span>< / label>< / TD>
< td>< input type =textid =emailaddressname =emailaddress>< / td>
< / tr>
< tr>
< td colspan =2>
< hr size =1.5color =#000000noshade>< / td>
< / tr>
< tr>
< td>< input type =submitid =field89name =field89class =c3value =Submit>< / td>
< td>< input type =resetid =field90name =field90class =c3value =Reset>< / td>
< / tr>
< / table>
< / form>
< / body>
< / html>

这里是php

 <?php 
if($ _POST ['submitted'] == 1){
$ errormsg =;
if($ _POST [first_name]){
$ first_name = $ _POST [first_name];
}
else {
$ errormsg =请输入您的名字;

if($ _POST [last_name]){
$ last_name = $ _POST [last_name];
}
else {
$ errormsg =请输入您的姓氏;
}
if($ _POST [ssn]){
$ ssn = $ _POST [ssn];
}
else {
$ errormsg =请输入您的社会安全号码;
}
if($ _POST [phone]){
$ phone = $ _POST [phone];
}
else {
$ errormsg =请输入您的电话号码;
}
if($ _POST [address]){
$ address = $ _POST [address];
}
else {
$ errormsg =请输入您的地址;
}
if($ _POST [city]){
$ city = $ _POST [city];
}
else {
$ errormsg =请输入你的城市;
}
if($ _POST [state]){
$ state = $ _POST [state];
}
else {
$ errormsg =请选择你的状态;
}
if($ _POST [zip]){
$ zip = $ _POST [zip];
}
else {
$ errormsg =请输入您的5位数字邮政编码;
}
if($ _POST [position]){
$ position = $ _POST [position];
}
else {
$ errormsg =如果开放讨论,请输入N / A;
}
if($ _POST [wage]){
$ wage = $ _POST [wage];
}
else {
$ errormsg =请输入0.00,如果开放讨论;
}
if($ _POST [Emergencycontactname]){
$ Emergencycontactname = $ _POST [Emergencycontactname];
}
else {
$ errormsg =请输入紧急联络人的姓名;

if($ _POST [Emergencycontactaddress]){
$ Emergencycontactaddress = $ _POST [address];
}
else {
$ errormsg =请输入您的紧急联系人地址;
}
if($ _POST [Emergencycontactcity]){
$ Emergencycontactcity = $ _POST [Emergencycontactcity];
}
else {
$ errormsg =请输入您的紧急联系人的城市;
}
if($ _POST [Emergencycontactstate]){
$ Emergencycontactstate = $ _POST [Emergencycontactstate];
}
else {
$ errormsg =请选择您的紧急联系人的状态;
}
if($ _POST [Emergencycontactzip]){
$ Emergencycontactzip = $ _POST [Emergencycontactzip];
}
else {
$ errormsg =请输入紧急联络人的5位数字邮政编码;
}
if($ _POST [Emergencycontactphone]){
$ Emergencycontactphone = $ _POST [Emergencycontactphone];
}
else {
$ errormsg =请输入紧急联络人的电话号码;
}
if($ _POST [hightest]){
$ highest = $ _POST [highest];
}
else {
$ errormsg =请输入您的最高教育水平;
}
if($ _POST [degree]){
$ degree = $ _POST [degree];
}
else {
$ errormsg =如果没有,请输入N / A;
}
if($ _POST [age]){
$ age = $ _POST [age];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [problems]){
$ problems = $ _POST [problems];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [shiftwork]){
$ shiftwork = $ _POST [shiftwork];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [学徒制]){
$学徒制= $ _POST [学徒制];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [disabled]){
$ disabled = $ _POST [disabled];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [ifyes]){
$ ifyes = $ _POST [ifyes];
}
else {
$ errormsg =如果您对上述问题回答否,请放置N / A;
}
if($ _POST [容纳]){
容纳= $ _POST [容纳];
}
else {
$ errormsg =如果您对上述问题回答不适用,请放置N / A;
}
if($ _POST [experience]){
$ experience = $ _POST [experience];
}
else {
$ errormsg =请输入是或否;
}
if($ _POST [ifyes2]){
$ ifyes2 = $ _POST [ifyes2];
}
else {
$ errormsg =如果您对上述问题回答否,请放置N / A;
}
if($ _POST [cname]){
$ cname = $ _POST [cname];
}
else {
$ errormsg =请输入公司名称;
}
if($ _POST [caddress]){
$ caddress = $ _POST [caddress];
}
else {
$ errormsg =请输入公司地址;
}
if($ _POST [cphone]){
$ cphone = $ _POST [cphone];
}
else {
$ errormsg =请输入公司电话号码;
}
if($ _POST [ccperson]){
$ ccperson = $ _POST [ccperson];
}
else {
$ errormsg =请输入联系人姓名;
}
if($ _POST [ctype]){
$ ctype = $ _POST [ctype];
}
else {
$ errormsg =请输入工作类型;
}
if($ _POST [cwage]){
$ cwage = $ _POST [cwage];
}
else {
$ errormsg =请输入赚取的工资;
}
if($ _POST [cstart]){
$ cstart = $ _POST [cstart];
}
else {
$ errormsg =请输入开始日期;

if($ _POST [cend]){
$ cend = $ _POST [cend];
}
else {
$ errormsg =请输入结束日期;
}
if($ _POST [creason]){
$ creason = $ _POST [creason];
}
else {
$ errormsg =请输入离开原因;
}
if($ _POST [cname2]){
$ cname2 = $ _POST [cname2];
}
else {
$ errormsg =请输入公司名称或输入N / A;

if($ _POST [caddress2]){
$ caddress2 = $ _POST [caddress2];
}
else {
$ errormsg =请输入公司地址,或输入N / A;

if($ _POST [cphone2]){
$ cphone2 = $ _POST [cphone2];
}
else {
$ errormsg =请输入公司电话号码,或输入N / A;
}
if($ _POST [ccperson2]){
$ ccperson2 = $ _POST [ccperson2];
}
else {
$ errormsg =请输入联系人姓名,或输入N / A;
}
if($ _POST [ctype2]){
$ ctype2 = $ _POST [ctype2];
}
else {
$ errormsg =请输入工作类型或输入N / A;
}
if($ _POST [cwage2]){
$ cwage2 = $ _POST [cwage2];
}
else {
$ errormsg =请输入赚取的工资,或输入N / A;

if($ _POST [cstart2]){
$ cstart2 = $ _POST [cstart2];
}
else {
$ errormsg =请输入开始日期或输入N / A;

if($ _POST [cend2]){
$ cend2 = $ _POST [cend2];
}
else {
$ errormsg =请输入结束日期,或输入N / A;
}
if($ _POST [creason2]){
$ creason2 = $ _POST [creason2];
}
else {
$ errormsg =请输入离开原因或输入N / A;
}
if($ _POST [cname3]){
$ cname3 = $ _POST [cname3];
}
else {
$ errormsg =请输入公司名称或输入N / A;

if($ _POST [caddress3]){
$ caddress3 = $ _POST [caddress3];
}
else {
$ errormsg =请输入公司地址,或输入N / A;

if($ _POST [cphone3]){
$ cphone3 = $ _POST [cphone3];
}
else {
$ errormsg =请输入公司电话号码,或输入N / A;

if($ _POST [ccperson3]){
$ ccperson3 = $ _POST [ccperson3];
}
else {
$ errormsg =请输入联系人姓名,或输入N / A;

if($ _POST [ctype3]){
$ ctype3 = $ _POST [ctype3];
}
else {
$ errormsg =请输入工作类型或输入N / A;
}
if($ _POST [cwage3]){
$ cwage3 = $ _POST [cwage3];
}
else {
$ errormsg =请输入赚取的工资,或输入N / A;
}
if($ _POST [cstart3]){
$ cstart3 = $ _POST [cstart3];
}
else {
$ errormsg =请输入开始日期或输入N / A;

if($ _POST [cend3]){
$ cend3 = $ _POST [cend3];
}
else {
$ errormsg =请输入结束日期,或输入N / A;
}
if($ _POST [creason3]){
$ creason3 = $ _POST [creason3];
}
else {
$ errormsg =请输入离开原因或输入N / A;
}
if($ _POST [maywe]){
$ maywe = $ _POST [maywe];
}
else {
$ errormsg =输入您不希望我们联系的公司的名称,或者输入,确定全部;
}
if($ _POST [additional]){
$ additional = $ _POST [additional];
}
else {
$ errormsg =如果没有任何附加信息,请输入N / A;
}
if($ _POST [electronicsignfn]){
$ electronicsignfn = $ _POST [electronicsignfn];
## Heading ##}
else {
$ errormsg =请输入您的全名;
}
if($ _POST [electronicsignssn]){
$ electronicsignssn = $ _POST [electronicsignssn];
}
else {
$ errormsg =请输入您的社会安全号码;
}
if($ _POST [emailaddress]){
$ emailaddress = $ _POST [emailaddress];
}
else {
$ errormsg =请输入您的电子邮件地址;
}
else {
if($ errormsg){//如果已经有错误,则添加下一个错误
$ errormsg = $ errormsg;
} else {
}
}
}
?>


解决方案

有几件事情需要按顺序发生让你的PHP阅读表单数据。首先,正如Waygood所建议的那样,将$ _POST值更改为传入变量名称的单引号是一个好主意。

  //例如:
$ _POST [address];

//应改为:
$ _POST ['address'];第二,如约翰所回答的那样,没有任何参考文献到 HTML表单中传递的提交的值,您需要在表单中添加一个隐藏的输入(在您的标签之间的任意位置),其值为1你的第一个声明是真实的,以便让其他php代码执行。

 <! - 将此输入标记放置在任意位置在您的html中打开和关闭窗体标签之间 - > 
< form method =POSTaction =your_submission_page.php>
< input type =hiddenname =submittedvalue =1/>
< / form>

最后,最佳做法通知使用者所有的​​错误在表格中,以便在能够提交表格之前不会出现错误。你应该做的是建立一个错误消息的动态数组,检查是否有任何错误,然后显示全部。

 <?php 
//为错误消息创建一个动态数组,然后将其发回给显示它们的表单

//以下是您的代码示例动态数组内置
$ error_msgs = array();
$ error = 0; //错误标志

if($ _POST ['cwage2']){
$ cwage2 = $ _POST ['cwage2'];
} else {
$ error_msgs [] =请输入赚取的工资,或输入N / A;
$ errors ++; //标记让代码知道有错误,在每种情况下使用
}

if($ _POST ['cstart2']){
$ cstart2 = $ _POST [ 'cstart2'];
} else {
$ error_msgs [] =请输入开始日期,或输入N / A;
$ errors ++; //标记让代码知道有错误,在每种情况下使用
}

//最后在最后检查是否有任何错误并将它们全部显示
if($ errors> 0){
//首先显示错误的数量
echoThere were。 $错误。 在您提交的错误中,请更正它们。< br />;

//然后显示错误数组
foreach($ error_msgs as& $ msg){
echo $ msg。 <峰; br /> 中;

} else {
//在这里添加代码以提交表单,但是你想要

}

?>


I have been trying to make this form validate before sending an email to my company. It will not validate the form, it will just send it whenever someone clicks submit. No validation is happening, I don't know what to do about this.

Here is a little of the form

<tr>
<td><label for="reason3">Reason for Leaving?</label></td>
<td><input type="text" id="reason3" name="reason3" class="c3"></td>
</tr>
<tr>
<td colspan="2">
<hr size="1.5" color="#000000" noshade></td>
</tr>
<tr>
<td><label for="maywe">May we contact the employers listed above?<br>
If not, indicate which you do not wish us to contact:</label></td>
<td><input type="text" id="maywe" name="maywe" class="c3"></td>
</tr>
<tr>
<td><label for="additional">Any additonal information you would like us to<br>
consider when reviewing your application?</label></td>
<td><input type="text" id="additional" name="additional" class="c3"></td>
</tr>
<tr>
<td colspan="2">
<hr size="1.5" color="#000000" noshade></td>
</tr>
<tr>
<td colspan="2">
<div class="c2">
<hr size="1.5" color="#000000" noshade>
        The above information is true and complete to the best of my knowledge. Should I become<br>
employed by <a href="http://www.creativeurethanes.com/">Creative Urethanes, Inc.,</a> any false statements on this application may be<br>
considered sufficient cause for dismissal.<br>
        I understand that filling out this application does not indicate that there are necessarily any<br>
vacant positions at this time, nor does it in any way obligate this Company.<br>
        I acknowledge that I have read Creative Urethanes' <a href="Memo.html">Memo on Right to Know</a>. <input type="checkbox" name="Yes" value="Yes"><span class="c1"><sup><i>*</i></sup></span><br>
<br></div>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1.5" color="#000000" noshade></td>
</tr>
<tr>
<td colspan="2">Sign electronically with your full name and SSN.</td>
</tr>
<tr>
<td><label for="electronicsignfn"><u>Full</u> <u>Name</u><span class="c1"><sup><i>*</i></sup></span></label></td>
<td><input type="text" id="electronicsignfn" name="electonicsignfn" class="c3"></td>
</tr>
<tr>
<td><label for="electronicsignssn"><u>S.S.N.</u><span class="c1"><sup><i>*</i></sup></span></label></td>
<td><input type="text" id="electronicsignssn" name="electronicsignssn" class="c3"></td>
</tr>
<tr>
<td><label for="emailaddress"><u>Email</u> <u>Address</u><span class="c1"><sup><i>*</i></sup></span></label></td>
<td><input type="text" id="emailaddress" name="emailaddress"></td>
</tr>
<tr>
<td colspan="2">
<hr size="1.5" color="#000000" noshade></td>
</tr>
<tr>
<td><input type="submit" id="field89" name="field89" class="c3" value="Submit"></td>
<td><input type="reset" id="field90" name="field90" class="c3" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>

Here is the php

<?php
if ($_POST['submitted']==1) {
$errormsg = "";
if ($_POST[first_name]){
$first_name = $_POST[first_name];
}
else{
$errormsg = "Please enter your first name";
}
if ($_POST[last_name]){
$last_name = $_POST[last_name];
}
else{
$errormsg = "Please enter your last name";
}
if ($_POST[ssn]){
$ssn = $_POST[ssn];
}
else{
$errormsg = "Please enter your Social Security Number";
}
if ($_POST[phone]){
$phone = $_POST[phone];
}
else{
$errormsg = "Please enter your phone number";
}
if ($_POST[address]){
$address = $_POST[address];
}
else{
$errormsg = "Please enter your address";
}
if ($_POST[city]){
$city = $_POST[city];
}
else{
$errormsg = "Please enter your city";
}
if ($_POST[state]){
$state = $_POST[state];
}
else{
$errormsg = "Please select your state";
}
if ($_POST[zip]){
$zip = $_POST[zip];
}
else{
$errormsg = "Please enter your 5 digit zip code";
}
if ($_POST[position]){
$position = $_POST[position];
}
else{
$errormsg = "Please enter N/A if open for discussion";
}
if ($_POST[wage]){
$wage = $_POST[wage];
}
else{
$errormsg = "Please enter 0.00 if open for discussion";
}
if ($_POST[Emergencycontactname]){
$Emergencycontactname = $_POST[Emergencycontactname];
}
else{
$errormsg = "Please enter your emergency contact's name";
}
if ($_POST[Emergencycontactaddress]){
$Emergencycontactaddress = $_POST[address];
}
else{
$errormsg = "Please enter your emergency contact's address";
}
if ($_POST[Emergencycontactcity]){
$Emergencycontactcity = $_POST[Emergencycontactcity];
}
else{
$errormsg = "Please enter your emergency contact's city";
}
if ($_POST[Emergencycontactstate]){
$Emergencycontactstate = $_POST[Emergencycontactstate];
}
else{
$errormsg = "Please select your Emergency contact's state";
}
if ($_POST[Emergencycontactzip]){
$Emergencycontactzip = $_POST[Emergencycontactzip];
}
else{
$errormsg = "Please enter your emergency contact's 5 digit zip code";
}
if ($_POST[Emergencycontactphone]){
$Emergencycontactphone = $_POST[Emergencycontactphone];
}
else{
$errormsg = "Please enter your emergency contact's phone number";
}
if ($_POST[hightest]){
$highest = $_POST[highest];
}
else{
$errormsg = "Please enter your highest level of education";
}
if ($_POST[degree]){
$degree = $_POST[degree];
}
else{
$errormsg = "Please enter N/A if none";
}
if ($_POST[age]){
$age = $_POST[age];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[problems]){
$problems = $_POST[problems];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[shiftwork]){
$shiftwork = $_POST[shiftwork];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[apprenticeship]){
$apprenticeship = $_POST[apprenticeship];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[disabilities]){
$disabilities = $_POST[disabilities];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[ifyes]){
$ifyes = $_POST[ifyes];
}
else{
$errormsg = "if you answered no to above question, put N/A";
}
if ($_POST[accommodate]){
$accommodate = $_POST[accommodate];
}
else{
$errormsg = "if you answered N/A to above question, put N/A";
}
if ($_POST[experience]){
$experience = $_POST[experience];
}
else{
$errormsg = "Please enter yes or no";
}
if ($_POST[ifyes2]){
$ifyes2 = $_POST[ifyes2];
}
else{
$errormsg = "if you answered no to above question, put N/A";
}
if ($_POST[cname]){
$cname = $_POST[cname];
}
else{
$errormsg = "Please enter company name";
}
if ($_POST[caddress]){
$caddress = $_POST[caddress];
}
else{
$errormsg = "Please enter company address";
}
if ($_POST[cphone]){
$cphone = $_POST[cphone];
}
else{
$errormsg = "Please enter company phone number";
}
if ($_POST[ccperson]){
$ccperson = $_POST[ccperson];
}
else{
$errormsg = "Please enter contact person's name";
}
if ($_POST[ctype]){
$ctype = $_POST[ctype];
}
else{
$errormsg = "Please enter type of work";
}
if ($_POST[cwage]){
$cwage = $_POST[cwage];
}
else{
$errormsg = "Please enter wage earned";
}
if ($_POST[cstart]){
$cstart = $_POST[cstart];
}
else{
$errormsg = "Please enter date started";
}
if ($_POST[cend]){
$cend = $_POST[cend];
}
else{
$errormsg = "Please enter date ended";
}
if ($_POST[creason]){
$creason = $_POST[creason];
}
else{
$errormsg = "Please enter reason for leaving";
}
if ($_POST[cname2]){
$cname2 = $_POST[cname2];
}
else{
$errormsg = "Please enter company name, or type N/A";
}
if ($_POST[caddress2]){
$caddress2 = $_POST[caddress2];
}
else{
$errormsg = "Please enter company address, or type N/A";
}
if ($_POST[cphone2]){
$cphone2 = $_POST[cphone2];
}
else{
$errormsg = "Please enter company phone number, or type N/A";
}
if ($_POST[ccperson2]){
$ccperson2 = $_POST[ccperson2];
}
else{
$errormsg = "Please enter contact person's name, or type N/A";
}
if ($_POST[ctype2]){
$ctype2 = $_POST[ctype2];
}
else{
$errormsg = "Please enter type of work, or type N/A";
}
if ($_POST[cwage2]){
$cwage2 = $_POST[cwage2];
}
else{
$errormsg = "Please enter wage earned, or type N/A";
}
if ($_POST[cstart2]){
$cstart2 = $_POST[cstart2];
}
else{
$errormsg = "Please enter date started, or type N/A";
}
if ($_POST[cend2]){
$cend2 = $_POST[cend2];
}
else{
$errormsg = "Please enter date ended, or type N/A";
}
if ($_POST[creason2]){
$creason2 = $_POST[creason2];
}
else{
$errormsg = "Please enter reason for leaving, or type N/A";
}
if ($_POST[cname3]){
$cname3 = $_POST[cname3];
}
else{
$errormsg = "Please enter company name, or type N/A";
}
if ($_POST[caddress3]){
$caddress3 = $_POST[caddress3];
}
else{
$errormsg = "Please enter company address, or type N/A";
}
if ($_POST[cphone3]){
$cphone3 = $_POST[cphone3];
}
else{
$errormsg = "Please enter company phone number, or type N/A";
}
if ($_POST[ccperson3]){
$ccperson3 = $_POST[ccperson3];
}
else{
$errormsg = "Please enter contact person's name, or type N/A";
}
if ($_POST[ctype3]){
$ctype3 = $_POST[ctype3];
}
else{
$errormsg = "Please enter type of work, or type N/A";
}
if ($_POST[cwage3]){
$cwage3 = $_POST[cwage3];
}
else{
$errormsg = "Please enter wage earned, or type N/A";
}
if ($_POST[cstart3]){
$cstart3 = $_POST[cstart3];
}
else{
$errormsg = "Please enter date started, or type N/A";
}
if ($_POST[cend3]){
$cend3 = $_POST[cend3];
}
else{
$errormsg = "Please enter date ended, or type N/A";
}
if ($_POST[creason3]){
$creason3 = $_POST[creason3];
}
else{
$errormsg = "Please enter reason for leaving, or type N/A";
}
if ($_POST[maywe]){
$maywe = $_POST[maywe];
}
else{
$errormsg = "Type names of companies you do not want us to contact, or type, ok all";
}
if ($_POST[additional]){
$additional = $_POST[additional];
}
else{
$errormsg = "Type N/A if you do not have any additional information";
}
if ($_POST[electronicsignfn]){
$electronicsignfn = $_POST[electronicsignfn];
## Heading ##    }
else{
$errormsg = "Please enter your full name";
}
if ($_POST[electronicsignssn]){
$electronicsignssn = $_POST[electronicsignssn];
}
else{
$errormsg = "Please enter your Social Security Number";
}
if ($_POST[emailaddress]){
$emailaddress = $_POST[emailaddress];
}
else{
$errormsg = "Please enter your email address";
}
else{
if ($errormsg){ //if there is already an error, add next error
$errormsg = $errormsg;
}else{
}
}
}
?>

解决方案

There are a few things that need to happen in order for your PHP to read the form data. First, as Waygood suggested, it is a good idea to change your $_POST values to have single quotes around the passed variable name.

//For example:
$_POST[address]; 

// Should change to:
$_POST['address']; //Notice the single quotes around the word address

Secondly, as answered by John, there is no reference to the passed submitted value in your html form, you'll want to add a hidden input in your form (anywhere between your tags) that holds the value of 1 to make your first statement true in order for the rest of your php code to execute.

<!-- Put this input tag anywhere between your opening and closing form tags in your html -->
<form method="POST" action="your_submission_page.php">
    <input type="hidden" name="submitted" value="1" />
</form>

Finally, it's good practice to notify the user of ALL of the errors in the form so that they don't experience error after error before being able to submit the form. What you should be doing is building a dynamic array of error messages, checking to see if there are any errors and then displaying them all.

<?php
    // Create a dynamic array for the error messages and validate everything before sending them back to the form that shows them

    // Here is a sample of your code with the dynamic array built in
    $error_msgs = array ();   
    $error = 0; //Error flag     

    if ($_POST['cwage2']){
        $cwage2 = $_POST['cwage2'];
    } else {
        $error_msgs[] = "Please enter wage earned, or type N/A";
        $errors++; //Flag to let the code know that there are errors, used in every case
    }

    if ($_POST['cstart2']){
        $cstart2 = $_POST['cstart2'];
    } else {
        $error_msgs[] = "Please enter date started, or type N/A";
        $errors++; //Flag to let the code know that there are errors, used in every case
    }

    // Finally at the end, check to see if there are any errors and display them all
    if ($errors > 0) {
        //Display the amount of errors first
        echo "There were " . $errors . " errors in your submission, please correct them.<br/>";

        //Then display your error array
        foreach ($error_msgs as &$msg) {                
            echo $msg . "<br/>"; 
        }
    } else {
        // Add code here to submit the form however you'd like

    }

?>

这篇关于为什么php不能用于我的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆