SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: forms

  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am designing a website for someone and I'm learning how to build forms. What I'd like
    to do now is have only 8 of the 12 fields be required. Plus if someone does not fill in a
    field, they will go to an error page that I have created, not the default. Is this possible?

    To see the page with the form.... http://canadianhomeworker.com/formtest.html

    Thanks for any help ~~ Deb

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Deb,

    I think you're probably better off using some clientside javascript to check the fields. If everthings ok the form gets submitted otherwise a dialog box is popped up telling the user what the problem is.

    Try the following link for more info:
    http://www.builder.com/Programming/S....dir1.SS042298

    Shane

  3. #3
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course, there's always the problem of "what if the user doesn't have javascript enabled?" -- While it's not an option for everybody, I prefer to do my validation on the server-side.

  4. #4
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Duluth, MN USA
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I've done is just put in a bunch of if/else statements in the form processing script. I have my forms setup to go through two scripts. One to check the data to make sure everything is filled in properly and then display a message if something is missing. If all the required fields are filled in, then it will display the data entered for the form-filler-outer to confirm and then send it to the script that writes the data to a file. What follows are the sections of my form processing script that checks the fields. I'm sure there is a cleaner way to do this with arrays but I'm still getting my feet wet with perl and haven't had a lot of free time to spend learning more.
    I have the script set up so that if the surfer wants me to mail a catalog to them they have to give me thier address or if they want me to take them off my mailinglist we need their name and address info wo we can remove the right person.

    Code:
    sub data_check {
    	if ($catalog eq "yes") {
    		&catalog;
    }
    	if ($mailinglist eq "add" || $mailinglist eq "remove") {
    		&mailinglist;
    }
    	if (($fname eq "") || ($email eq "")) {
              print "Content-type: text/html\n\n";
              
    	print qq~
    	$msgheader~;
    	print qq~
    	  <H3> Empty Fields</H3>
    	  <P>Press your browser's BACK button 
    	  to return to the form and please fill 
    	  in the required fields.
    ~;
    print qq~
    $footer~;
    exit;
            }
    }
    
    sub catalog {
    		if ($fname eq "" || $lname eq "" || $address eq "" || $city eq "" || $state eq "" || $zip eq "") {
              print "Content-type: text/html\n\n";
    			print qq~
    			$msgheader~;
    			print qq~
    		  <H3> Empty Fields</H3>
    		  <P>Press your browser's BACK button 
    		  to return to the form and please fill 
    		  in the required fields.  We need your name and address to send you a catalog.
    			~;
    		print qq~
    		$footer~;
    		exit; }
    }
    
    sub mailinglist {
    		if ($fname eq "" || $lname eq "" || $address eq "" || $city eq "" || $state eq "" || $zip eq "") {
              print "Content-type: text/html\n\n";
    	print qq~
    	$msgheader~;
    	print qq~
    	  <H3> Empty Fields</H3>
    	  <P>Press your browser's BACK button 
    	  to return to the form and please fill 
    	  in the required fields.  We need your name and address to $addorremove our list.
    ~;
    print qq~
    $footer~;
    exit; }
    }
    I hope this helps
    --Bill
    Lake Superior Smokin' Brews Make It Different: Brew Your Own!
    L'Etoile du Nord Web Development Providing Real Direction in a Virtual World
    MSN IM: smokinbrews-AT-hotmail-DOT-com
    Brewin', Vintin' & Smokin' Forums Moderator

  5. #5
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd agree that server side validation would be best but if you look at Debs page you'll see that she's using a cgi script. I'm guessing that Debs not familiar with server side processing.

    Therefore, I figured that a bit of Javascript would be best as it would be fairly easy to implement and would catch most of the submissions.

    Shane

  6. #6
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello....Shane you are right, I am not familiar with server side processing, but
    willing to learn. I did take a look at the url you posted earlier. I might give it a try. Or
    maybe go with client side javascript...not sure yet.

    Sahti, thanks for taking the time to post the script for me

    So to get this straight, using cgi script, I can't have "only certain" fields be required if I
    want a custom error page and not the default? I did play around with the code and
    determined I can make all the fields be required and I can do the custom error page OR
    have a few of the fields be required but I would get a default page. We don't need all
    the fields to be required.

    Thanks for everyone's advice ~~ Deb

  7. #7
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again....posting again to say I got it worked out now using cgi script. I can have
    whichever fields I want required and have a custom error page instead of the default
    error page. All I did was add these 2 lines to the code and it worked....
    <input type=hidden name="required" value="email,phone,etc">
    <input type=hidden name="missing_fields_redirect" value="http://your.host.com/error.html">

    I wasn't sure how to use the code I had before, but I figured it out...yay! Thanks for all
    the help before. One of these days I will have to try server side scripts....someday!

    Deb


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
  •