Menu icon Foundation
Form Handling

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

Thank you

formscriptsdata

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

<!--contactform-->
  <div class="large-10 large-centered small-12 columns contactform">
   <form method="post" action="<?php echo home_url(); ?>/contact-success">
    <fieldset>
     <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>
      <div class="large-6 small-12 columns">
       <label>Surname</label>
       <input name="surname" type="text" placeholder="Surname">
      </div>
     </div>

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

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

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

    </fieldset>
   </form>
  </div>
  <!--contactform end-->

Success page

  <?php 
   $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) ; 
   if($sent) 
   {print "Your mail was sent successfully"; }
   else 
   {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: http://foundation.zurb.com/forum/posts/2451-submitting-a-form

If you have anymore questions post on that thread!

Ben Siegfried about 4 years ago

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

ProcessForm3 is the one you'd want to use.

http://www.mindpalette.com/archives/processform/