Help adding required fields on email form script...

Discussion in 'PHP' started by AshDaFlash, May 25, 2009.

  1. #1
    Hi,

    Can someone help provide directions on how i can add selective required fields on my make a request page (http://www.pcmechanix.ca/request.htm)?

    Thanks,

    Ash
     
    AshDaFlash, May 25, 2009 IP
  2. sssharlasss

    sssharlasss Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your question is a bit vague.

    But maybe this'll help you:

    
    
    <?php
    
    session_start();
    
    $field = mysql_real_escape_string($_GET['field']);
    
    if(!$field){
    	// WTF?  The field is empty!
    	$_SESSION['form_error'] = "You must fill in the \"field\" field, jerk.";
    	header("Location: http://www.pcmechanix.ca/request.php");
    }else{
    	//All is good!
    	header("Location: http://www.pcmechanix.ca/success.php");
    }
    
    ?>
    
    
    Code (markup):
    Oh, and, you'll have to use PHP for the above example, in case you didn't notice.

    Can't use PHP? Then you're going to have to use JavaScript. Search "JavaScript form validation" on Google. It's not as secure as using a server-side check, but it'll work in a pinch.
     
    sssharlasss, May 25, 2009 IP
  3. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    You need to edit the file sendrequest.php
    add something like the following (you need to alter it to match the field NAMES on request.htm)

    
    session_start();
    $error = 'no';
    if (!isset($_POST['firstname'])){
        header('location: request.htm?e=1');
        exit();
        }
    if ((!isset($_POST['email'])) || (!strstr($_POST['email'],'@')) || (!strstr($_POST['email'],'.'))){
        header('location: request.htm?e=2');
        exit();
        }
    //etc...
    
    PHP:
     
    tguillea, May 25, 2009 IP