Agreement form on a website?

Discussion in 'Web Design and Development' started by definitive, May 19, 2011.

  1. definitive macrumors 68000

    definitive

    Joined:
    Aug 4, 2008
    #1
    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).
     
  2. mkmDesign macrumors newbie

    Joined:
    Feb 21, 2010
    Location:
    Scotland
    #2
    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.
     
  3. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #3
    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.
     
  4. mkmDesign macrumors newbie

    Joined:
    Feb 21, 2010
    Location:
    Scotland
    #4
    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.
     
  5. IgnatiusTheKing macrumors 68040

    IgnatiusTheKing

    Joined:
    Nov 17, 2007
    Location:
    das Fort
    #5
    There are lots of services out there, many of them free, that will do that for you.
     
  6. definitive thread starter macrumors 68000

    definitive

    Joined:
    Aug 4, 2008
    #6
    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.
     
  7. IgnatiusTheKing macrumors 68040

    IgnatiusTheKing

    Joined:
    Nov 17, 2007
    Location:
    das Fort
    #7
    Check out jotform and email me form. Both have free versions, neither of which is perfect, but they're a decent place to start.
     
  8. shaneg macrumors newbie

    Joined:
    Aug 17, 2011
    #8
    JotForm's site is down now! :eek:
     

Share This Page