Actress Posted July 4, 2006 Share Posted July 4, 2006 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 More sharing options...
yoshida Posted July 4, 2006 Share Posted July 4, 2006 //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 More sharing options...
Actress Posted July 4, 2006 Author Share Posted July 4, 2006 Hey thanks a lot! I'll try that! Link to comment Share on other sites More sharing options...
Little Goat Posted July 5, 2006 Share Posted July 5, 2006 //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;}<{POST_SNAPBACK}> 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 More sharing options...
yoshida Posted July 6, 2006 Share Posted July 6, 2006 you forgot the quote at the end of that string. don't forget to add one before you test it.<{POST_SNAPBACK}> 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now