Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
在wordpress的front-page.php页面中创建自定义联系人表单_Php_Wordpress_Contact Form - Fatal编程技术网

在wordpress的front-page.php页面中创建自定义联系人表单

在wordpress的front-page.php页面中创建自定义联系人表单,php,wordpress,contact-form,Php,Wordpress,Contact Form,我在一个网站的主题工作,并希望创建自定义的联系形式。这是wordpress中的一个单页主题,我在其中有front-page.php文件,在其中的contact部分中我实现了表单 <form action="<?php the_permalink(); ?>" id="contactForm" method="POST"> <div class=&qu

我在一个网站的主题工作,并希望创建自定义的联系形式。这是wordpress中的一个单页主题,我在其中有front-page.php文件,在其中的contact部分中我实现了表单

<form action="<?php the_permalink(); ?>" id="contactForm" method="POST">

                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Name" name="name" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" class="required requiredField" />
                                <?php if ($nameError != '') { ?>
                                    <span class="error"><?= $nameError; ?></span>
                                <?php } ?>
                            </div>
                            <br />
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Email" name="email" id="email" value="<?php if (isset($_POST['email']))  echo $_POST['email']; ?>" class="required requiredField email" />
                                <?php if ($emailError != '') { ?>
                                    <span class="error"><?= $emailError; ?></span>
                                <?php } ?>
                            </div>
                            <br />
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Phone" name="phone" id="phone" value="<?php if (isset($_POST['phone']))  echo $_POST['phone']; ?>" class="required requiredField phone" />
                                <?php if ($phoneError != '') { ?>
                                    <span class="error"><?= $phoneError; ?></span>
                                <?php } ?>
                            </div>
                            <br />
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Messege" name="messege" id="messegeText" rows="2" class="required requiredField">
                                <?php if (isset($_POST['messege'])) {
                                    if (function_exists('stripslashes')) {
                                        echo stripslashes($_POST['messege']);
                                    } else {
                                        echo $_POST['messege'];
                                    }
                                } ?></textarea>
                                <?php if ($messegeError != '') { ?>
                                    <span class="error"><?= $messegeError; ?></span>
                                <?php } ?>
                            </div>
                            <div class="form-group">
                                <input class="btn btn-danger" type="submit" value="Send"></input>
                            </div>
                            <input type="hidden" name="submitted" id="submitted" value="true" />
                        </form>

<?php
if(isset($_POST['submitted'])) {
    if(trim($_POST['name']) === '') {
        $nameError = 'Please enter your name.';
        $hasError = true;
    } else {
        $name = trim($_POST['name']);
    }
    
    if(trim($_POST['phone']) === '') {
        $phoneError = 'Please enter your phone number.';
        $hasError = true;
    } else {
        $phone = trim($_POST['phone']);
    }

    if(trim($_POST['email']) === '')  {
        $emailError = 'Please enter your email address.';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
        $emailError = 'You entered an invalid email address.';
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    if(trim($_POST['messege']) === '') {
        $messegeError = 'Please enter a message.';
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $messege = stripslashes(trim($_POST['messege']));
        } else {
            $messege = trim($_POST['messege']);
        }
    }

    if(!isset($hasError)) {
        $emailTo = get_option('emailid');
        if (!isset($emailTo) || ($emailTo == '') ){
            $emailTo = get_option('emailid');
        }
        $subject = '[PHP Snippets] From '.$name;
        $body = "Name: $name \n\nEmail: $email \n\Messege: $messege";
        $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
        wp_mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }

} ?>

尝试从表单中删除
操作
属性,这将指示浏览器提交到当前page@ChrisHaas没有同样的事情发生