Coding Thread, PHP form in Coding and Web Development; Have a couple of issues with this form and wondering if anyone can help?
Here's the code I am using: ...
6th May 2011, 09:39 AM #1
Have a couple of issues with this form and wondering if anyone can help?
Here's the code I am using: http://pastebin.com/bEkihqgY
- If you submit the empty form, the error validation returns back "Please fill in all the required fields and submit again." twice. How can I get it to say the name of the fields instead?
- The profanity filter doesn't work on the name field?
Last edited by Edu-IT; 6th May 2011 at 09:41 AM.
6th May 2011, 09:48 AM #2
Instead of outputting the error message each time an empty field is found you need to build a variable containing the names of the empty fields.
Then after you have looped through POST values test if the variable contains any value and then output the error message including the list of empty fields.
Another approach I have used in the past is to output a standard message and use css to highlight the empty fields by filling them with red or changing the border...
6th May 2011, 09:51 AM #3
Something like this would also do it
BTW I like the 'orgasim' entry in your profanity list...shows how good sex-ed is doesn't it
if (!isset($_POST[$field]) || empty($_POST[$field]))
$error_msg .= "Please fill in the $field field and submit again.\r\n";
6th May 2011, 11:48 AM #4
Not me who wrote the code. ;-)
I'll adjust that, thanks. Any ideas why profanity doesn't cover the name field?
Last edited by Edu-IT; 6th May 2011 at 11:55 AM.
6th May 2011, 02:10 PM #5
Any ideas how to get the form to entered retain data on error?
6th May 2011, 02:30 PM #6
Originally Posted by Edu-IT
<input type="text" name="email" value="<?php if (isset($_POST['email']) && !empty($_POST['email'])) echo $_POST['email']; ?>" />
Last edited by Hightower; 6th May 2011 at 02:54 PM.
6th May 2011, 02:46 PM #7
shouldn't that last echo be outputting 'email'?
Originally Posted by Hightower
6th May 2011, 02:54 PM #8
It's 3 o'clock on Friday on the first week back from a 2 week break.....
Originally Posted by CESIL
6th May 2011, 03:13 PM #9
I assume there's one of those for each field?
6th May 2011, 03:19 PM #10
Yep, just stick the PHP script in the value for each one and change the $_POST['email'] to whatever
Originally Posted by Edu-IT
6th May 2011, 04:07 PM #11
26th May 2011, 11:55 AM #12
Where am I going wrong here? Certain fields don't line up.
Tutor group, pupils sport, pupils achievement all display out of line.
26th May 2011, 12:02 PM #13
Also I notice that on submit, the fields still retain data. Can this be cleared on successful submit?
And finally, how do I get the text area to retain entered data on error?
26th May 2011, 12:09 PM #14
Simple answer to first bit :P
Your length of the name is too long. Change "name if different" etc, to "name" and it'll realign, as it's pushing it onto new line. (or incease size of column)
26th May 2011, 12:11 PM #15
That's not it unfortunately.
Originally Posted by Steve21
Edit: Another thing I just noticed, when a field is not submitted, is it possible to just have the 'please complete all fields' messages displayed just once?
Last edited by Edu-IT; 26th May 2011 at 12:13 PM.
By tomgrindle in forum Web Development
Last Post: 26th April 2011, 12:26 PM
By glennda in forum Web Development
Last Post: 17th November 2010, 10:22 AM
By BarryWAaMC in forum Coding
Last Post: 31st March 2010, 11:32 AM
By _Bat_ in forum Web Development
Last Post: 25th March 2009, 11:39 AM
By thesk8rjesus in forum Web Development
Last Post: 21st January 2009, 12:09 AM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)