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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.