Jump to content


Photo

Form Validation Bug


  • Please log in to reply
2 replies to this topic

#1 hanlonj

hanlonj
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 20 September 2006 - 07:57 PM

Hi,

I am validating a form on a page using the
$_SERVER[PHP_SELF}
superglobal.

I check for empty fields and display an error beside the field that is empty so the user will know what to correct (as per usual on a website).My problem is that when the page loads initially, the form is as you would expect empty. so the errors appear upon first loading of the page.

I realise this is easy to fix but the solution is escaping me at the moment.

Can anyone help?

John

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 20 September 2006 - 08:28 PM

that means, you are probably running your validation without ever seeing whether or not the form has been submitted. let's say you have your submit button simply named "submit", you'll need to wrap your entire validation and processing within something like this:
<?php
if (isset($_POST['submit'])) {
  // process your form here.
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 hanlonj

hanlonj
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 20 September 2006 - 08:37 PM

that means, you are probably running your validation without ever seeing whether or not the form has been submitted. let's say you have your submit button simply named "submit", you'll need to wrap your entire validation and processing within something like this:

<?php
if (isset($_POST['submit'])) {
  // process your form here.
}
?>


Excellent, worked no problem.

Thank  you very much.

John





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users