FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Form validation, seperate file, or same as form?





coeus
When you guys make pages with forms, do you have it goto a process page or stay on the same page as the form?

When you have errors, it seems like the most user-friendly thing to do would be to highlight the form elements with a little description of the error next to it. The question is what do you think is the best way to handle such a thing? Without Javascript?

I would like to avoid Javascript, but it seems almost necessary to do some of the cool features you see all over the web, darn you people surfing with it disabled!
AftershockVibe
You MUST do it behind the scenes at the very least (ie in PHP or similar) for the reason you said.

Not everyone has JavaScript enabled so if you only use that for validation then they can submit whatever they like and your system will not be looking for it!

Doing anything in JavaScript is therefore only for user-friendliness. I've have personally never bothered to use JavaScript.
DjinniFire
Well I haven't seen a lot of form validation scripts and such so concept wise this is what I thought of:

Form -> Second File that checks each input (If error set a value to "error") -> Redisplay Form with either confirmation or error. (using include)

So if name is error maybe a variable called $hlname will be set to 1 and in the form that u redisplay you have
if($hlname==1){
set class to highlight
}

Or something (very unspecific but its a general concept)
badai
i try to use javascript as much as possible, in the same form. i use onsubmit function, that way the form is check right there and then on client side so it will be faster and no bandwidth or server time is wasted.
kv
Here is how I code it.

1. Post the form to the same page
2. Check if it is submitted. If yes, process submit first.
3. If there was no error, redirect it to onother page (or whatever action you want to take)
4. If there was error, continue to display the same form again, along with error message and previous values

Here is a sample code
Code:


<?
$submit=$_POST['submit'];
$err="";
if(isset($submit)) //The form has been submitted
{
   //process form here

  if($err=="")//No error
  {
     //redirect to onother page
  }
}

/*if you have reached here, either it was not posted (first time), or there was an error
   In any case, display the form, possibly with old values */

if($err!="") //display error if there was one
  echo "There was an error: $err";

?>
<form>
<!-- your form contents here. post it to same file -->
</form>
Ranfaroth
coeus wrote:
When you guys make pages with forms, do you have it goto a process page or stay on the same page as the form?
Same page, for the reasons you gave.
Related topics
check box validation
Creating a new Operating System
News and Comment system!
HTML help needed
HTML
How to use only one directory for image files ?
Form validation
A very good PHP MySQL Tutorial
[*RESOLVED*]Please close for me
Form Processing
Portable Games
POST a form in the Same page
upload file to server using html form and CGI C
Simple Form Validation [solved]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.