Jump to content

required fields?


Actress

Recommended Posts

Hi!I have this form in an html page, and the form sends the data to a php file I made out from a tutorial, so it can transfer the data of the fields to my mail.But I'm having a bit of trouble on doing someting that I thought of, especially when people were leaving blank fields. I wanted to have a little code that verified if the required fields were filled.I would rather if the code could be directly on the html page instead of the php, but it really doesn't matter, as long as it works. I tried somethings I found on the net, but neither work... I'm a newbie in php... Can you help me?Many thanks!Ana.

Link to comment
Share on other sites

//handler;$field1=$_POST['field1'];$field2=$_POST['field2'];$field3=$_POST['field3']; 	 if ($field1 == "" || $field2 == "" || $field3 == "") {//checks if a user actually filled all required fieldsecho "you didn't fill all required fields;} 	 else {query or other action here;}

In short, this code checks if any posted value is blank ("") and executes the appropriate script. The required fields should be separated as shown.

Link to comment
Share on other sites

//handler;$field1=$_POST['field1'];$field2=$_POST['field2'];$field3=$_POST['field3'];   if ($field1 == "" || $field2 == "" || $field3 == "") {//checks if a user actually filled all required fieldsecho "you didn't fill all required fields;}   else {query or other action here;}

you forgot the quote at the end of that string. don't forget to add one before you test it.
Link to comment
Share on other sites

you forgot the quote at the end of that string. don't forget to add one before you test it.

Ah thanks... it's very wise to keep an extra set of eyes on quotes and such.Luckily, my editor has code highlighting (all quoted text turns pink) so I guess I'm a bit lazy that way. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...