View Full Version : required form fields (without javascript)

May 11th, 2010, 06:13 AM
How do you make certain fields required without using javascript?


May 11th, 2010, 12:07 PM
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.

May 11th, 2010, 08:57 PM
Could you help me out with the structure of that?

I tried doing this:

header('previous page');

// 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. :)

code beginner
May 11th, 2010, 09:55 PM
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.

May 12th, 2010, 01:45 AM
Thanks. :) I'll check it out and let you know how it goes.

May 12th, 2010, 01:57 AM
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.

May 12th, 2010, 09:13 PM
I found something much better than regular expressions if you have PHP5. filter_var is a lot less work.