Advanced Search

Results 1 to 2 of 2

Thread: Php form a field will only submit when a certain number is entered

  1. #1
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Php form a field will only submit when a certain number is entered

    Hello.
    I am wanting to spam proof my form simply by adding a field where a certain value like '11' is entered for it to submit. The text would be 'seven + four =' and the value must be 11 or the form will not submit.

    How do I do this easily?

    Thanks

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    243
    Thanks
    1
    Thanked 18 Times in 18 Posts

    Default

    Use a if() to check if the field is equal to 11. You will need to obviously add the field in your form named check_number in order for this to work.
    PHP Code:
    if (isset($_POST['submit']))
    {
    $check $_POST['check_number'];
         if (
    $check=="11")
         {
          
    /* Subject and Email Variables */

         
    $emailSubject 'Basement Studio Web Enquiry'
         
    $webMaster 'info@basement-studios.co.uk';

         
    /* Gathering Data Variables */

         
    $nameField $_POST['name'];
         
    $emailField $_POST['email'];
         
    $artistField $_POST['artist'];
         
    $subjectField $_POST['subject'];
         
    $messageField $_POST['message'];

         
    $body ="
         <br><hr><br>
         Name: 
    $name<br>
         Email: 
    $email<br>
         Artist: 
    $artist<br>
         Subject: 
    $subject<br>
         Message: 
    $message<br>
         "
    ;

         
    $headers "From: $email\r\n";
         
    $headers .= "Content-type: text/html\r\n";
         
    $seccess mail($webMaster$emailSubject$body$headers);

         
    /* Results as HTML */

         
    $theResults ="<html><body>Congrats!!</body></html>";
          echo 
    "$theResults";
         }
         else
         {
         echo 
    "You did not enter the correct number";
         }

    Honestly I have no idea what your piece of code - <<EOD means, but it was causing the code not to read right for what I told you to do so I removed that and you can put it back in if you need it but I have never seen that before.
    Last edited by fastsol1; 10-03-2010 at 02:58 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •