Page 1 of 1

Form handling question???

Posted: Wed Apr 19, 2006 10:38 am
by abrusky
What is the best way to make a field in a form required?

I have tried but I can't get it to work properly.

Posted: Wed Apr 19, 2006 10:42 am
by feyd
That would depend on the validation of that field's submitted data. What, specifically, did you try?

Posted: Wed Apr 19, 2006 12:10 pm
by s.dot
You'll want to check if the value sent is empty (or isset if its a checkbox or radio button), then do whatever based on the outcome of that

Code: Select all

if(empty($_POST['requiredField'])){
    //  They didn't fill it in.
    die('Sorry, you must fill in all fields');
} else {
    //  it was filled in
    //  continue processing form
}

Posted: Wed Apr 19, 2006 12:15 pm
by abrusky
This is what i tried but it either gives me a blank page or completes the redirect

Code: Select all

<?
 
        ini_set("SMTP","mail19.webcontrolcenter.com");
        ini_set("smtp_port","8889");
        ini_set("sendmail_from","InfoPack@postcardmania.com");
        ini_set ('display_errors', 1);
        
        error_reporting(E_ALL & ~E_NOTICE);
        
               
         // order.php
         
         //error_reporting(0);
         
         // Check if form was submitted properly.
         
         if ( isset($_POST['submit'])){
           
           $problem = FALSE; // no problems so far
           
          // CHECK FOR EACH VALUE
          
          if (empty ($_POST['email'])) {
          $problem = TRUE;
          print ('<p><b>Please enter your email address.</b></p>');
          }
          
          if (!$problem){ //if there aren't ant problems
          
          @mail("x@xxx.com", "Form Submission", $text, "From:      Website"); 
         
          $url = "http://www.xxxx.com/reportdownloaddent.asp";
          Header("Location: $url");
          
          } else { // forgot a field
          
          print ('<p>Please go back and try again.</p>');
          }
         
         } // End of handle form IF
         
         $text = 
        
        " Form Submission.
        
        Details:
        
        Date:                        " . date('D d M Y - h:i a') ."
        Email:                       ". $_POST['email'] ."
        Company Name:                      ". $_POST['companyname'] ."
        Industry:                      ". $_POST['industry'] ."
        First Name:                      ". $_POST['contactfirstname'] ."
        Last Name:                      ". $_POST['contactlastname'] ."
        Address:                  ". $_POST['address'] ."
        City, St, Zip:             ". $_POST['city'] ." ". $_POST['state'] ." ". $_POST['zip'] ."
        Phone:                      ". $_POST['phone'] ."
        Fax:                   ". $_POST['fax'] ."
        
        How Referred:
        Marketing Code:                      ". $_POST['marketing_code'] ."
        Referred By:                      ". $_POST['referred_by'] ."
        Search Engine:                      ". $_POST['search_engine'] ."
        Magazine:                      ". $_POST['magazine'] ."
        
        Currently use Direct Mail:    ". $_POST['mail'] ."
        If so this often:    ". $_POST['howoften'] ."
                           
        Other types of marketing used:     ". $_POST['types'] ."
        Contact me:      ". $_POST['contactme'] ."
         ";
         
        
   ?>

Posted: Wed Apr 19, 2006 12:26 pm
by John Cartwright
please make your code readable next time by atleast indenting properly..

this is likely the reason why your page isn't working as expected, because its very dificult to follow your logic

Re: Form handling question???

Posted: Wed Apr 19, 2006 4:29 pm
by Zythan
Hello abrusky,

Take a look here and tell me if this is what you are trying to do.

http://zfutura.free.fr/fillform/inscriptfive.php

Regards.

Zythan