Form handling question???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Form handling question???

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That would depend on the validation of that field's submitted data. What, specifically, did you try?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
abrusky
Forum Newbie
Posts: 15
Joined: Wed Apr 05, 2006 2:05 pm
Location: Clearwater FL

Post 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'] ."
         ";
         
        
   ?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Zythan
Forum Newbie
Posts: 16
Joined: Wed Apr 12, 2006 3:13 am

Re: Form handling question???

Post 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
Post Reply