SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Form Valid

  1. #1
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Valid

    I'm not sure how to make it so when somebody submits a form if the form has a empty field it says that they didn't fill it in and it won't be updated. can somebody help me on that plz.

  2. #2
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always create a hidden field called form:
    <input type="hidden" name="form" value="1">

    Then at the end of the script I do this:
    PHP Code:
    if($form)
    {
     
    // If form was submitted, check for errors and submit to database
      
    errorCheck();
      
    databaseEntry();
    }
    else
    {
     
    // Else print form
     
    printForm()

    Then, errorCheck() looks something like this:
    PHP Code:
    function errorCheck()
    {
     global $adcopy;
            if (empty($adcopy))
            {
                $errormsg .= "<li><font color=red>No ad copy specified.</font><br>\n";
                $error = 1;
            }
            
            if ($error)
            {
            printHeader("$sitetitle - Error Adding New Member", "Error Adding New Member");
            ?>
            
            The following errors have occurred while processing your request:<br>
            <ul>
            <?php print $errormsg?>
            </ul>
            <p>
            Please press the back button on your browser and submit the member information again.  Thank you.
            <p>
            
            <?php
            printFooter
    ();   
            
            exit;
            }
    Last edited by RKuhle; Jun 18, 2001 at 18:01.
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  3. #3
    SitePoint Enthusiast drisley's Avatar
    Join Date
    Jun 2001
    Location
    Florida
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The key to the function is to use the empty() function to see if the variable is defined.

    if (empty($var)) {
    echo "this";
    }

    Just put that into your form processor.
    David Risley
    Web Developer, Web Publisher, Blogger, Tech Dude
    PC Mechanic | WebbyOnline


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
  •