SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Forms & PHP

  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey everyone!

    I was wondering if there is some sort of coding to make sure there is data in forms before submissions.

    I'm planning on creating a request board type idea on my website (using Php & MySQL), but I want to ensure that each field (for the form) has DATA in it, so people HAVE to put in information for each field. How do I go about this?

    Thanks in advance!

    Leo Chan

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if ($text == "" || $username == "") { }
    ...etc.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris...I think it sounds like he is looking for a verification on the page itself...that would be Javascript right?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do it with JS. Personally, I prefer the PHP way of doing it since you don't have to worry about whether they have JS turned on or not. I also like doing it this way since I can get the errors listed in the page I output..

    Code:
    if (!isset($name))
    {
       $errmsg .= "<li>Please fill in your name\n";
       $errors = true;
    }
    if (!isset($phone))
    {
       $errmsg .= "<li>Please fill in your phone number\n";
       $errors = true;
    }
    
    if ($errors)
    {
       echo $errmsg;
       // re-display the form
    }

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or

    PHP Code:
    if (!isset($name)) $errmsg[] = "Please fill in your name";
    if (!isset(
    $phone)) $errmsg[] = "Please fill in your phone";

    if (
    $errormsg) {
       foreach(
    $errormsg as $val) {
          
    printf('<li>%s%s'$val"\n");
          }
       
    // re-display the form


    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •