Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单错误消息无法正常工作,表单无法提交_Php_Forms_Email_Validation - Fatal编程技术网

Php 表单错误消息无法正常工作,表单无法提交

Php 表单错误消息无法正常工作,表单无法提交,php,forms,email,validation,Php,Forms,Email,Validation,我对表单验证和处理非常陌生,事实上,这是我的第一次尝试,我创建了一个简单的联系人表单,其中包含必需的文本字段、注释文本区域和两个单选按钮。我已经完成了许多基本的教程,并使用PHP编写了脚本。我遇到的问题是,如果表单未填写,当我单击“提交”时,我会被引导到一个新页面,其中有一条错误消息,说我需要填写我的姓名。但是,如果我填写我的姓名并单击submit,我会收到相同的消息,而不是为下一个字段指定的错误消息。当所有字段都归档时,我甚至收到了这个消息。这是我的密码: <?php $

我对表单验证和处理非常陌生,事实上,这是我的第一次尝试,我创建了一个简单的联系人表单,其中包含必需的文本字段、注释文本区域和两个单选按钮。我已经完成了许多基本的教程,并使用PHP编写了脚本。我遇到的问题是,如果表单未填写,当我单击“提交”时,我会被引导到一个新页面,其中有一条错误消息,说我需要填写我的姓名。但是,如果我填写我的姓名并单击submit,我会收到相同的消息,而不是为下一个字段指定的错误消息。当所有字段都归档时,我甚至收到了这个消息。这是我的密码:

    <?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();
    }
    ?>

请更正以下错误:
请帮帮我。我不知道我做错了什么。提前感谢:)

以下是HTML表单:

    <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>

    Vorname/Name* 固定格式* 函数* 地址* PLZ/Ort* Telefon* 移动电话* 电子邮件*
  • Wir sind bereits Kunde* 青年成就 不
  • Kontaktieren Sie uns* 电话电报 每封电子邮件 Bemerkungen* Nächste Messe数据*
  • Standgrösse平方米*
  • *迪泽·费尔德·沃登·本蒂格特

问题在于,如果($problem&&strlen($data)==0)这个if
总是正确的-这让我觉得你在
$\u POST['name']
中没有任何价值-放一些消息,看看你有什么信息。

问题是这个if
如果($problem&&strlen($data)==0)
总是正确的-这让我觉得你在
$\u POST['name']
中没有任何价值-放一些消息,看看你在那里有什么信息。

我已经尝试过这个代码,它在我这边起作用了!尝试utf8编码您的文本,表单输入名称等

<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();
}
?>

请更正以下错误:

我已经尝试过这个代码,它对我来说很有效!尝试utf8编码您的文本,表单输入名称等

<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();
}
?>

请更正以下错误:

check\u input函数是如何调用的,我想我们这里缺少一些代码。check\u input函数是如何调用的,我想我们这里缺少一些代码。谢谢你的帮助,但我仍然有问题。。。也许问题在我的from代码中?我在原始问题中添加了表格谢谢你的帮助,但我仍然有问题。。。可能问题在我的from代码中?我在原始问题中添加了表单