所有必填字段出现PHP错误-但所有字段都已插入

所有必填字段出现PHP错误-但所有字段都已插入,php,html,forms,requiredfieldvalidator,Php,Html,Forms,Requiredfieldvalidator,我正在用一个php处理程序(signup form handler.php)制作一个注册表单(signup.html)。 但我好像做错了什么 这是我的代码: $errors = ''; $myemail = 'example@domain.com';//<-----Put Your email address here. if(empty($_POST['FirstName']) || empty($_POST['LastName']) || empty($_POST[

我正在用一个php处理程序(signup form handler.php)制作一个注册表单(signup.html)。 但我好像做错了什么

这是我的代码:

$errors = '';
$myemail = 'example@domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName'])  || 
   empty($_POST['LastName'])  || 
   empty($_POST['City'])  || 
   empty($_POST['Country']))
{
    $errors .= "\n Error: all fields are required";
}

$FirstName = $_POST['FirstName']; 
$LastName = $_POST['LastName'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$Int1 = $_POST['Int1'];       // <---- Here's what seems to be the issue
$Int2 = $_POST['Int2'];       // <---- Here's what seems to be the issue 

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Udfyldelse af test på Gamification: $FirstName";
    $email_body = "Du har fået en ny besvarelse. ".
    "Her er besvarelserne:\n Fornavn: $FirstName \n Efternavn: $LastName \n By: $City \n Land $Country \n".
    "De fire personlige interesser: $Int1 og $Int2"; 

    $headers = "From: $myemail\n"; 

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
} 
$errors='';

$myemail='10〕example@domain.com';// 默认方法是GET。将表单方法设置为POST:

<form id="contact_form" name="contact_form" action="signup-form-handler.php" method="POST">


因此,基本上您没有将值传递给脚本。如果要使用GET方法,请将$\u POST的所有实例切换为$\u GET,您可以保持表单不变。

在输入Int1和Int2中,缺少属性type

好的,对于初学者来说,粗体标记的“”已去除摩擦,请使用“

如果你把这个添加到你的php页面上,它会工作的,尽管我不能理解丹麦人的意思,但还是可以使用这个表单。这是一个单页解决方案,不需要HTML文件

<?php
$form = '<form id="contact_form" name="contact_form" action="'.$_SERVER['PHP_SELF'].'" method="post" >


<!-- Personlige oplysninger -->


    <h3>Personlige oplysninger<a class="info" href="#" title="Testing"><img style="height: 15px; width: 15px; margin-left: 5px;" alt="Time" src="img/signup_form/info_simple.png"></a></h3>


    <strong>Mit navn er</strong>
    <input class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" type="text" maxlength="60">
    <input class="user_field" placeholder="efternavn" id="LastName" name="LastName" type="text" maxlength="60" >
    <input type="text" class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" >
    <strong>og bor i</strong>
    <input class="user_field" placeholder="indsæt by" id="City" name="City" type="text" maxlength="60" >
    <strong>,</strong>
    <input class="user_field" placeholder="indsæt land" id="Country" name="Country" type="text" maxlength="60" >
    <strong>Beskriv dig selv med 4 interesser</strong>
    <input type="text" id="Int1" name="Int1" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 1" >
    <input type="text" id="Int2" name="Int2" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 2" >

    <input  type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 3" >

    <input type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 4" >
    <input type="submit" name="submit" value="Enter">
</form>';
if (isset ($_POST['submit'])){
$errors = '';
$myemail = 'example@domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName'])  || 
empty($_POST['LastName'])  || 
empty($_POST['City'])  || 
empty($_POST['Country']))
{
$errors .= "\n Error: all fields are required";
$display = $errors.$form;
}else{
$FirstName = $_POST['FirstName']; 
$LastName = $_POST['LastName'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$Int1 = $_POST['Int1'];       // <---- Here's what seems to be the issue
$Int2 = $_POST['Int2'];       // <---- Here's what seems to be the issue 

$to = $myemail; 
$email_subject = "Udfyldelse af test på Gamification: $FirstName";
$email_body = "Du har fået en ny besvarelse. ".
"Her er besvarelserne:\n Fornavn: $FirstName \n Efternavn: $LastName \n By: $City \n Land $Country \n".
"De fire personlige interesser: $Int1 og $Int2"; 

$headers = "From: $myemail\n"; 

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
}else{
$display = $errors.$form;   
}

echo $display;
?>


您能同时包含相关的HTML代码吗?编辑:我也不清楚确切的错误是什么。我想你真的想写
$Int1=isset($\u POST['Int1'])$_POST['Int1']:空给你,帕特。这足够了吗?如果我插入$Int1=isset($\u POST['Int1'])$_POST['Int1']:空;而不是$Int1=$_POST['Int1'];我得到了相同的答案“错误:所有字段都是必需的”。@Patvia在我更好地解释了这个问题之前,希望没问题:)我也发现了这个问题,因为你可以继续往下看。那没关系。只是意味着它将默认为一种“文本”;没错,text是默认类型,type不是必需的属性;-)所以我应该在html文件中添加method=“post”,并在php中将$\u post更改为$\u GET?还是我还是弄错了?我本想做一件或另一件,而不是两件都做。为简单起见,只需将method=“POST”添加到表单标记中。我将“ed method=“POST”添加到表单的html标记中,现在它可以工作了:)非常感谢@ksealey:)这似乎是一个很好的方法。非常简单:)我是php新手,所以我跟随一个教程。谢谢分享:)没问题,你甚至可以进行错误检查。。。。例子。。。。。。if(empty(empty)(empty(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(empty)(请告诉我们您的名字);$display=$errors.$form;}if(empty)(请告诉我们您的姓氏){$errors.=“请告诉我们您的姓氏”;$display=$errors.$form;}
<?php
$form = '<form id="contact_form" name="contact_form" action="'.$_SERVER['PHP_SELF'].'" method="post" >


<!-- Personlige oplysninger -->


    <h3>Personlige oplysninger<a class="info" href="#" title="Testing"><img style="height: 15px; width: 15px; margin-left: 5px;" alt="Time" src="img/signup_form/info_simple.png"></a></h3>


    <strong>Mit navn er</strong>
    <input class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" type="text" maxlength="60">
    <input class="user_field" placeholder="efternavn" id="LastName" name="LastName" type="text" maxlength="60" >
    <input type="text" class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" >
    <strong>og bor i</strong>
    <input class="user_field" placeholder="indsæt by" id="City" name="City" type="text" maxlength="60" >
    <strong>,</strong>
    <input class="user_field" placeholder="indsæt land" id="Country" name="Country" type="text" maxlength="60" >
    <strong>Beskriv dig selv med 4 interesser</strong>
    <input type="text" id="Int1" name="Int1" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 1" >
    <input type="text" id="Int2" name="Int2" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 2" >

    <input  type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 3" >

    <input type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 4" >
    <input type="submit" name="submit" value="Enter">
</form>';
if (isset ($_POST['submit'])){
$errors = '';
$myemail = 'example@domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName'])  || 
empty($_POST['LastName'])  || 
empty($_POST['City'])  || 
empty($_POST['Country']))
{
$errors .= "\n Error: all fields are required";
$display = $errors.$form;
}else{
$FirstName = $_POST['FirstName']; 
$LastName = $_POST['LastName'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$Int1 = $_POST['Int1'];       // <---- Here's what seems to be the issue
$Int2 = $_POST['Int2'];       // <---- Here's what seems to be the issue 

$to = $myemail; 
$email_subject = "Udfyldelse af test på Gamification: $FirstName";
$email_body = "Du har fået en ny besvarelse. ".
"Her er besvarelserne:\n Fornavn: $FirstName \n Efternavn: $LastName \n By: $City \n Land $Country \n".
"De fire personlige interesser: $Int1 og $Int2"; 

$headers = "From: $myemail\n"; 

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
}else{
$display = $errors.$form;   
}

echo $display;
?>