Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts

    required form fields (without javascript)

    How do you make certain fields required without using javascript?

    Thanks.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    By using PHP validation (which you should use anyway). If a certain field isn’t filled out (i. e. empty) the form processing script redirects back to the page and displays a message.

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Could you help me out with the structure of that?

    I tried doing this:

    Code:
    		
    
                    if($_POST['firstname']==''){
    			header('previous page');
    		}
    		
    		
    		if($_POST){
    		// store input
    		header('next page');		
    		}
    The error checking part (the first part) only redirects to the previous page if I remove the bottom part. I guess that's how header works. Is there a way to make header redirect immediately? Or is there some other thing I'm doing wrong?

    Thanks.

  • #4
    Regular Coder
    Join Date
    Sep 2009
    Posts
    167
    Thanks
    15
    Thanked 1 Time in 1 Post
    you want to learn about "regular expressions". those are the coding instruction sets that tell a program to accept or reject a user input based on how you set up the regular expression(s).

    if you know about regular expressions already, then my post isn't offering anything new. however, if you haven't heard about regular expressions, it's the exact thing you should look into in detail.

    the term itself is misleading and too general. if they were called gatekeeper instructions, it would be much more obvious.

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks. I'll check it out and let you know how it goes.

  • #6
    New Coder
    Join Date
    May 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I checked out regular expressions. I see that's how I can validate the input, but can someone help me with the file structure? See above post.

    Should I be using exit() or something like that? Thanks.

    edit: I see that you must put exit; after a redirect if you don't want the code below it to execute.
    Last edited by cmw000; 05-12-2010 at 07:07 PM.

  • #7
    New Coder
    Join Date
    May 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I found something much better than regular expressions if you have PHP5. filter_var is a lot less work.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •