...

View Full Version : required form fields (without javascript)



cmw000
05-11-2010, 06:13 AM
How do you make certain fields required without using javascript?

Thanks.

VIPStephan
05-11-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.

cmw000
05-11-2010, 08:57 PM
Could you help me out with the structure of that?

I tried doing this:




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

code beginner
05-11-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.

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

cmw000
05-12-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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum