Jump to content

Form Validation Bug


hanlonj

Recommended Posts

Hi,

I am validating a form on a page using the [code]$_SERVER[PHP_SELF}[/code]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
Link to comment
https://forums.phpfreaks.com/topic/21456-form-validation-bug/
Share on other sites

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:
[code]
<?php
if (isset($_POST['submit'])) {
  // process your form here.
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/21456-form-validation-bug/#findComment-95658
Share on other sites

[quote author=obsidian link=topic=108839.msg438297#msg438297 date=1158784082]
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:
[code]
<?php
if (isset($_POST['submit'])) {
  // process your form here.
}
?>
[/code]
[/quote]

Excellent, worked no problem.

Thank  you very much.

John
Link to comment
https://forums.phpfreaks.com/topic/21456-form-validation-bug/#findComment-95662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.