0

On my website there is a contact form on footer which is working fine.
Site Blog is on wordpress have same contact form.

I don't wan't to create working again for wordpress contact form

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

Form action="/yocreativ/contact-us" which is the route of my laravel app.
When i submit the form it says.

The page has expired due to inactivity.
Please refresh and try again.

Community
  • 1
  • 1
Ashutosh Sharma
  • 434
  • 1
  • 9
  • 20
  • Possible duplicate of [laravel 5.5 The page has expired due to inactivity. Please refresh and try again](https://stackoverflow.com/questions/46149561/laravel-5-5-the-page-has-expired-due-to-inactivity-please-refresh-and-try-again) – Maraboc May 10 '18 at 08:21
  • @Ashutosh, Please check my answer is work for you? – PPL May 10 '18 at 10:48

1 Answers1

0

For WordPress wp_nonce_field and wp_verify_nonce field to verify.

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

Form field like:

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

In action file

<?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
}
PPL
  • 6,357
  • 1
  • 11
  • 30