Jump to content

Validate form errors before going to action page


Last

Recommended Posts

I have created a  php page that needs to validate  if the amount entered is less than 100or must return an error. My function though does not get called when clicking submit  even if the  amount is less than 100 but link goes straight to the actioned page

<html>
<head></head>
<title></title>
<style>
    .error {color: #FF0000;}
</style>
<body>

<?php
function test_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
$amountErr="";
$amount="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    if (["amount"]<100)
    {$amountErr = "Value must be equal or greater than 100";}
    else
    {$amount = test_input(["amount"]);}
}

?>

<p><span class="error">*required field.</span></p>
<form action="https://www.moneybookers.com/app/payment.pl" method="post">
    <input type="hidden" name="pay_to_email" value="my email account"/>
    <input type="hidden" name="status_url" value="http://example.com/verify.php"/>
    <input type="hidden" name="return_url" value="return_page"/>
    <input type="hidden" name="language" value="EN"/>
    Amount:<input type="text" name="amount"/>
    <span class="error">*<?php echo $amountErr;?></span>
    <input type="hidden" name="currency" value="USD"/>
    <input type="hidden" name="detail1_description" value="YourApp"/>
    <input type="hidden" name="detail1_text" value="New Deposit"/><BR>
    <input type="submit" value="Deposit!"/>
</form>

</body>
</html>
Link to comment
Share on other sites

php code is executed on the server when the page is requested. so, all the php code you have shown has long since ran by the time the form code has been sent to and displayed in the browser.

 

to use php code to validate the data, you would need to have your form submit to the .php page, then build the form that the payment gateway expects with the action set to the payment gateway.

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.