Edu-IT Posted May 6, 2011 Posted May 6, 2011 (edited) 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 The problems: 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? Edited May 6, 2011 by Edu-IT
CESIL Posted May 6, 2011 Posted May 6, 2011 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...
CESIL Posted May 6, 2011 Posted May 6, 2011 Something like this would also do it if (!isset($_POST[$field]) || empty($_POST[$field])) $error_msg .= "Please fill in the $field field and submit again.\r\n"; } BTW I like the 'orgasim' entry in your profanity list...shows how good sex-ed is doesn't it
Edu-IT Posted May 6, 2011 Author Posted May 6, 2011 (edited) Not me who wrote the code. ;-) I'll adjust that, thanks. Any ideas why profanity doesn't cover the name field? Edited May 6, 2011 by Edu-IT
Edu-IT Posted May 6, 2011 Author Posted May 6, 2011 Any ideas how to get the form to entered retain data on error?
Hightower Posted May 6, 2011 Posted May 6, 2011 (edited) Any ideas how to get the form to entered retain data on error? Edited May 6, 2011 by Hightower
Hightower Posted May 6, 2011 Posted May 6, 2011 shouldn't that last echo be outputting 'email'? It's 3 o'clock on Friday on the first week back from a 2 week break.....
Hightower Posted May 6, 2011 Posted May 6, 2011 I assume there's one of those for each field? Yep, just stick the PHP script in the value for each one and change the $_POST['email'] to whatever
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 Where am I going wrong here? Certain fields don't line up. <br /> /*Contact form*/<br /> label {<br /> width:4em;<br /> float:left;<br /> text-align:right;<br /> margin-right:1.5em;<br /> display:block<br /> }<br /> .submit input {<br /> margin-left:4.5em;<br /> }<br /> input.text {<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> margin:2px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> textarea {<br /> border: 1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> margin: 2px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> fieldset {<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> padding: 4px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> }<br /> p.error, p.success {<br /> font-weight: bold;<br /> padding: 10px;<br /> border: 1px solid;<br /> }<br /> p.error {<br /> background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0]#ffc0c0[/url]<br /> color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900]#900[/url]<br /> }<br /> p.success {<br /> background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69]#b3ff69[/url]<br /> color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000]#4fa000[/url]<br /> }<br /> </pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post"> Name Pupils Name (if different) Tutor group Pupils sport/activity Pupils achievement E-mail </for Tutor group, pupils sport, pupils achievement all display out of line.
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 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?
Steve21 Posted May 26, 2011 Posted May 26, 2011 Simple answer to first bit 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) Steve
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 (edited) Simple answer to first bit 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) Steve That's not it unfortunately. 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? Edited May 26, 2011 by Edu-IT
Steve21 Posted May 26, 2011 Posted May 26, 2011 That's not it unfortunately. It is here Works fine. Try this: <br /> /*Contact form*/<br /> label {<br /> width:12em;<br /> float:left;<br /> text-align:right;<br /> margin-right:1.5em;<br /> display:block<br /> }<br /> .submit input {<br /> margin-left:4.5em;<br /> }<br /> input.text {<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> margin:2px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> textarea {<br /> border: 1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> margin: 2px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> fieldset {<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br /> padding: 4px;<br /> border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br /> }<br /> p.error, p.success {<br /> font-weight: bold;<br /> padding: 10px;<br /> border: 1px solid;<br /> }<br /> p.error {<br /> background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0]#ffc0c0[/url]<br /> color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900]#900[/url]<br /> }<br /> p.success {<br /> background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69]#b3ff69[/url]<br /> color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000]#4fa000[/url]<br /> }<br /> </pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post"> Name Pupils Name (if different) Tutor group Pupils sport/activity Pupils achievement E-mail </for Works fine in IE8 now. Steve
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 It is here Works fine. Try this: <br /> /*Contact form*/<br /> label {<br /> width:12em;<br /> float:left;<br /> text-align:right;<br /> margin-right:1.5em;<br /> display:block<br /> }<br /> .submit input {<br /> margin-left:4.5em;<br /> }<br /> input.text {<br /> border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br /> margin:2px;<br /> border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> textarea {<br /> border: 1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br /> margin: 2px;<br /> border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> fieldset {<br /> border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br /> padding: 4px;<br /> border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br /> }<br /> p.error, p.success {<br /> font-weight: bold;<br /> padding: 10px;<br /> border: 1px solid;<br /> }<br /> p.error {<br /> background: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0"]#ffc0c0[/url]<br /> color: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900"]#900[/url]<br /> }<br /> p.success {<br /> background: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69"]#b3ff69[/url]<br /> color: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000"]#4fa000[/url]<br /> }<br /> </pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post"> Name Pupils Name (if different) Tutor group Pupils sport/activity Pupils achievement E-mail </for Works fine in IE8 now. Steve [ATTACH=CONFIG]10268[/ATTACH] That worked, thanks. Must be something I did.
Steve21 Posted May 26, 2011 Posted May 26, 2011 That worked, thanks. Must be something I did. As I said Made label wider: width:12em; vs your 4em (or make names shorter) What was other issue, it doesn't clear on input? Steve
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 Perfect! Sorry. :-D Anyone help with the PHP stuff?
Steve21 Posted May 26, 2011 Posted May 26, 2011 Perfect! Sorry. :-D Anyone help with the PHP stuff? You should be able to do a: document.formname.reset(); After the submit to clear the boxes. Steve
Steve21 Posted May 26, 2011 Posted May 26, 2011 (edited) Where, sorry, after the closing fieldset? There's few ways to do it, but cleanest (Think that word exists!) Change: to Think that's right. (Obviously you need to put form name in though, which I don't think you did yet?) Steve Edited May 26, 2011 by Steve21
Steve21 Posted May 26, 2011 Posted May 26, 2011 That retains all data still. Have you named your form yet? Needs a named form to go against. In the original one it didn't have a name Can you post all what you're trying again please. Steve
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 Your name Pupils name (if different) Tutor group Pupils sport/activity Pupils achievement Your email address This is what I have.
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