Menu icon Foundation
Form Handling

Does anyone have any confirmed scripts for handling data submitted via a form?

Thank you


Does anyone have any confirmed scripts for handling data submitted via a form?

Thank you

Wing-Hou Chan over 5 years ago

Hi Charles,

This is a piece of code I use to submit data from a form to an email address. It's not too bad to use at the moment but it works.

The name attributes correspond to the variables in the success-page.

Page with form on

  <div class="large-10 large-centered small-12 columns contactform">
   <form method="post" action="<?php echo home_url(); ?>/contact-success">
     <legend>Contact Us</legend>

     <div class="row">
      <div class="large-6 small-12 columns">
       <label>First name</label>
       <input name="first_name" type="text" placeholder="First Name">
      <div class="large-6 small-12 columns">
       <input name="surname" type="text" placeholder="Surname">

     <div class="row">
      <div class="large-6 small-12 columns">
       <label>Email address</label>
       <input name="email_address" type="text" placeholder="Email address">
      <div class="large-6 small-12 columns">
       <label>Phone number</label>
       <input name="phone_number" type="text" placeholder="Phone number">

     <div class="row">
      <div class="large-12 small-12 columns">
       <label>Your Message</label>
       <textarea class="message" name="your_message" placeholder="Your message"></textarea>

     <div class="row">
      <div class="large-12 small-12 columns">
       <button class="submit" name="send" type="submit">Submit</button>

  <!--contactform end-->

Success page

   $to = "Your email address" ; 
   $subject = "" ; 
   $firstname = $_REQUEST['first_name'] ;
   $surname = $_REQUEST['surname'] ;
   $email = $_REQUEST['email_address'] ;
   $phone = $_REQUEST['phone_number'] ;
   $message = $_REQUEST['your_message'] ;
   $headers = "From: $email" ; 

   $totalmessage = "
       First name:    $firstname  \n
    Surname:    $surname  \n
    Email address:  $email    \n
    Phone number:  $phone    \n" ;

   $sent = mail($to, $subject, $totalmessage, $message, $headers) ; 
   {print "Your mail was sent successfully"; }
   {print "We encountered an error sending your mail"; }

I'll have to admit there are better form data handling scripts out there and I would love to see a better example, but for now you can use this one.

Daniel Walton about 5 years ago

where exactly does the success go in the code

Wing-Hou Chan about 5 years ago

Hey Daniel!

The success code goes into a new PHP file.

I've made a better tutorial for using this code, along with some improvements, here:

If you have anymore questions post on that thread!

Ben Siegfried over 4 years ago

I've used this one before, it works well.

ProcessForm3 is the one you'd want to use.