Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

definitive

macrumors 68020
Original poster
Aug 4, 2008
2,049
893
I'm trying to build a page where a person would enter some personal info in order to register for classes. It would contain their name, address, phone, several check boxes with a text entry lines, and at the bottom it would contain a check box for agreement. Then they'd submit the form, and the info would get sent through email.

Is there some kind of a PHP script already available that could do this? I don't know PHP, so coding it from scratch is out of the question at the moment. I've tried the fast secure contact form script, but it didn't exactly look presentable, and I couldn't achieve some of the things that I wanted out of the form. Plus the checkbox kept prompting me for data (which I don't require except that the checkbox be checked).
 

mkmDesign

macrumors newbie
Feb 21, 2010
15
0
Scotland
Hey,

This is pretty straight forward to do. Getting the information from the form and emailing it is easy enough, the more difficult side is validation, ensuring the user enters the correct data etc. You can do validation checks in the PHP script, or you can use Javascript to check the data before passing it to the PHP script. I prefer to use jQuery for validation before actioning the PHP script. I suppose it comes down to personnel preference.

Anyway, here's an example:

HTML Form:

Code:
<form method="POST" action="mail.php">
   <label>Name:</label>
   <input type="text" name="name" />
   <label>Phone:</label>
   <input type="text" name="phone" />
   <label>Address</label>
   <textarea name="address"></textarea>
   <input type="checkbox" name="checkbox" value="checkbox" />
   <input type="submit" value="Submit" />
</form>

PHP File:

PHP:
<?php
    //get details user entered and store them in variables
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $checkbox = $_POST['checkbox'];

   //check that checkbox has been ticked
   if($checkbox !== '1'){
       echo "Please select checkbox";
   }

    //check that data has been entered
    if(!isset($name) || !isset($phone) || !isset($address)){
        echo "Please enter some data";
    }
    else{
        //set the required information for the email to be sent 
        $to = "youremail@example.com";
        $subject = "New User";
        $message = $name . " has now registered on your site.  Their phone number is " . $phone . " and their address is " . $address;
        $header = "New user registered";

       //send the email
       mail($to, $subject, $message, $headers);
    }

?>

I've just written this of the top of my head and not actually tested it (I'm at work at the moment) but this should give you an idea of what you need.

If you can supply the code for the form you are using I would be able to explain exactly what you need in your PHP script.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I prefer to use jQuery for validation before actioning the PHP script.

You ALWAYS need to do validation on the server side. What happens if someone comes to your website with Javascript turned off and all your validation is done by jQuery? Answer: No validation occurs and you have opened yourself up to numerous bugs and attack vectors.

Sure you can validate on the client side with jQuery but you still need to validate on the server side as well. It is either server only or server and client validation but never client validation only.
 

mkmDesign

macrumors newbie
Feb 21, 2010
15
0
Scotland
You ALWAYS need to do validation on the server side. What happens if someone comes to your website with Javascript turned off and all your validation is done by jQuery? Answer: No validation occurs and you have opened yourself up to numerous bugs and attack vectors.

Sure you can validate on the client side with jQuery but you still need to validate on the server side as well. It is either server only or server and client validation but never client validation only.

Hey Cromulent,

Very well said, silly mistake to make. I always used to do validation solely server side, it's only recently I've starting doing both.
 

definitive

macrumors 68020
Original poster
Aug 4, 2008
2,049
893
There are lots of services out there, many of them free, that will do that for you.

Do you know of any services that do this for free? I've come across http://www.formsite.com but they charge $10/month for over 100 submissions, and $20/month for branding-free service, so that their ads aren't shown on your site. it's nice, and all, but the client who I'm doing this for does not want to spend the money on it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.