【问题标题】:Functioning of Wordpress Contact form to Laravel MethodWordpress 联系表单对 Laravel 方法的作用
【发布时间】:2018-05-10 08:10:27
【问题描述】:

在我的网站上,页脚上有一个联系表格,效果很好。
网站博客在 wordpress 上具有相同的联系表。

我不想再次为 wordpress 创建工作联系表

<form action="/yocreativ/contact-us" method="post">
                           <?php 
                                //Generate a random string.
                                $token = openssl_random_pseudo_bytes(20);
                                
                                //Convert the binary data into hexadecimal representation.
                                $token = bin2hex($token);
                                
                                //Print it out for example purposes.
                                // echo $token;
                            ?>
                            <input type="hidden" name="_token" value="<?php echo $token; ?>">
                                <div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
                                    <input type="text" name="name" class="form-control" id="name" placeholder="NAME" required="required">
                                </div>
                                <div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
                                    <input type="email" name="email" class="form-control" id="email" placeholder="EMAIL" required="required">
                                </div>
                                <div class="form-group col-lg-4 wow fadeInDown animated" data-wow-delay="0.2s">
                                    <input type="tel" name="phone" class="form-control" id="subject" placeholder="PHONE" pattern="^\d{3}\d{3}\d{4}$" required="required">
                                </div>
                                <div class="form-group col-lg-12 wow fadeInDown animated" data-wow-delay="0.2s">
                                    <textarea  name="message" id="message" cols="30" rows="5" placeholder="MESSAGE" required="required"></textarea>                              
                                </div>
                                <div class="row">
                                    <div class="col-lg-12">
                                        <button type="submit" class="btn contact-submit">SEND</button>
                                    </div>
                                </div>
                            </form>

表单 action="/yocreativ/contact-us" 这是我的 laravel 应用程序的路由。
当我提交它说的表格时。

页面因不活动而过期。
请刷新并重试。

【问题讨论】:

标签: wordpress laravel


【解决方案1】:

对于 WordPress 的 wp_nonce_field 和 wp_verify_nonce 字段进行验证。

https://codex.wordpress.org/Function_Reference/wp_nonce_field

表单字段如:

<form method="post">  
   <?php wp_nonce_field('name_of_my_action','name_of_nonce_field'); ?>
</form>

在行动文件中

<?php
if ( empty($_POST) || !wp_verify_nonce($_POST['name_of_nonce_field'],'name_of_my_action') )
{
   print 'Sorry, your nonce did not verify.';
   exit;
}
else
{
   // process form data
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 2015-08-31
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多