Forum Moderators: coopster

Message Too Old, No Replies

validation

         

nshack31

2:07 pm on Apr 13, 2005 (gmt 0)

10+ Year Member



i was using javascript to validate my register form but its not reliable. How can I validate fields in php so that, for example if username was blank it would print a message on the same page asking the username to enter a value?

I've been trying this for a while, im struggling as it seems i would have to write and IF statement for every field I need checking.

Please help
Thanks

jatar_k

4:12 pm on Apr 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe take a look at this thread
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]

covers the basics of testing submitted fields

mcibor

8:35 pm on Apr 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But still you need to write if for every input. However you can automate it a little bit with a function:

$name = "text1";
function check($name)
{
if(!isset($_POST[$name]) ¦¦ (empty($_POST[$name]))) return "Please fill in the $name field"; //or just echo it. But remember to use " quotes, not ' apostrophes!
}

Hope it helps!
Michal Cibor

PS You can do this in js as well, but remeber to place it before submiting the form. So don't put it in <input>s, but in <button onclick="js_check(); return false;">Bla</button>