Jump to content

Prevent submitting form before php validation succeed


kinaski

Recommended Posts

Hi all,

 

I would appreciate some help considering my php form validation script.

 

The code goes like this:

 

if (isset($_POST['Submit']))
{
    $validator = new FormValidator();
    $validator->addValidation("first_name","req","Please fill in Name");
    $validator->addValidation("email","email","The input for Email should be a valid email value");

    if($validator->ValidateForm())
    {
        echo "<h2>Validation Success!</h2>";
        $show_form=false;
    }
    else
    {
        echo "<B>Please fix folowing errors in the form:</B>";

        $error_hash = $validator->GetErrors();
        foreach($error_hash as $inpname => $inp_err)
        {
            echo "<p class=\"form_phperror\">$inpname : $inp_err</p>\n";
        }       
    }
}

<form name="test-form" id="test-form" action="http://other-server.com/submited-form.php" method="POST">
<div>
        <label for="first_name">Contact Person - First Name <span class="req">*</span></label>
        <input  id="first_name"  class="textfield required" maxlength="40" name="first_name" size="20" type="text" title="Please enter your first name." />
      </div>
      <div>
        <label for="email">Email <span class="req">*</span></label>
        <input  id="email" class="textfield required email" maxlength="80" name="email" size="20" type="text" title="Please enter your valid email address." />
      </div>
</form>

By the way I'm using http://www.html-form-guide.com/php-form/php-form-validation.html for the validation part.

 

What I'm not sure how to achieve is to stop the form from submitting before validation process finishes and is successful . Now it immediately goes to the form action page  http://other-server.com/submited-form.php not validating the script.

 

I want this to be a completely php server validation if possible, and not client javascript one. The thing that I need this functionality is that I'm submitting a form into an external server (a CRM system) and I dont ave an access there,  to modify the receiving script.

 

Thank you!

Link to comment
Share on other sites

I'm guessing that the processing page is expecting posted values - as a result, this isn't really possible. You can validate, or you can post the info to the next page, but you can't validate then post the info to the next page.  You can send data to the next page, either in a cookie, or in the URL, but if the processing page isn't set up to deal with that info, then you are out of luck.

Link to comment
Share on other sites

I'm guessing that the processing page is expecting posted values - as a result, this isn't really possible. You can validate, or you can post the info to the next page, but you can't validate then post the info to the next page.  You can send data to the next page, either in a cookie, or in the URL, but if the processing page isn't set up to deal with that info, then you are out of luck.

 

Thanks, I was actually afraid of that ... But I hoped there was a solution...

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.