php form validation help
I'm hoping someone can point me in the right direction.
I'd like to have a form that validates on the same page and has the errors come up adjacent to the input fields themselves.
I'm familiar with form validation, but I'm not sure how to go about scripting something like that.
And also I need it to only show the form if either the submit button hasn't been hit at all, or there are errors. Once the form is validated and comes up true, I wand the form to hide and a thank you message to come up.
Are there any tutorials out there on this? I find tons, but only to list error at the bottom of the page, etc...
Although I know that some don't agree with using tables to place form elements, I have used tables to do this with several forms with no problem. Although, I would say that the best thing to do would be to start with the skeleton of the form and the table, and then you can add the inner elements (checking for errors!!!). Something like the following would place the input area and the error message side by side:
As the user types, the page could validate on the fly
etc. etc. etc. etc. etc. etc.
(this.form.1_textarea could be changed to this.id so that you could create the form with a FOR loop):
<textarea name="1_textarea" id="1_textarea"
function validateFxn(checkField, errorField)
if(something about checkField)
else if(something else about checkField)
You can save the errors in an array using the applicable form field names as the keys. Then when re-outputting the form, check to see if there is an error for that field and output the desired HTML accordingly:
<label>Some Field: <input name='some_field' type='text' value='<?php
echo htmlentities($_POST['some_field'], ENT_QUOTES);
echo "<span class='error'>".htmlentities($errors['some_field'], ENT_QUOTES)."</span>";
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)