Jump to content

Validate input value against calculated value


kool_samule

Recommended Posts

Hi Chaps,

 

Need a bit of guidence with some PHP code.

 

I have a Query that estimates a quote ($price_total) for a job.

 

The estimate ($price_total) is the value of an input (jobquote), and the database is updated once the form is submitted (using a seperate script.php page).

 

What I need, is to validate the entered value of 'jobquote' against the estimated value of $price_total, just incase a 'custom' price has been agreed with a customer.

 

If the values are different, then I need an 'admin override' radio button (admin_quote enum('y','n')) to appear.

 

If someone can help or point me in the right direction, I'd be most grateful.

 

Cheers

Hi, should have been a bit clearer I guess,

$price_total=['calculation']
<input type='text' name='jobquote' id="count" class='price_warning' value="<?php echo number_format($price_total, 1, '.', '').'0'; ?>"/>

So $price_total is the default value of the input, but it can be changed, and if changed, i need the 'admin override' option to appear.. . .

Ok you need to create a hidden field called like "original_job_quote" and submit that with the form..

So when the form is submitted get it to check the 2 values;

echo '<input type="input" name="jobquote" value="'.$price_total.'" />
<input type="hidden" name="original_jobquote" value="'.$price_total.'" />';
// On Post //
if ($_POST['original_jobquote'] != $_POST['jobquote']) {
// They dont match
}

Got a bit further:

 

<input type='text' name='jobquote' value="<?php echo $price_total; ?>"/>
        <input type='hidden' name='original_jobquote' value="<?php echo $price_total; ?>"/>
        <?php
		if ($_POST['original_jobquote'] != $_POST['jobquote'])
			{ ?>
        		<span id="spryradio1">
        		<input type="radio" name="jobquoteadmin" value="y" id="radio" />Confirm<br />
        		<span class="radioRequiredMsg">Please confirm Admin Override</span></span>
        		<?php };
	?>

 

Problem 1. The information is '$_POST'ed to a script file, not to the page itself and at the moment, the $_POST takes place before the PHP validation takes place. If I remove the link to the script page, the validation works.

 

Problem 2. (link to script removed for testing) If I change the value (from the default 'original_quote'), then submit, the page reloads, the 'Confirm' radio button appears, but the value of 'job_quote' has reverted back thte default:

1. Start - job_quote = £350

2. Change - job_quote = £100

3. Submit

4. Page reloads - job_quote = £350, confirm appears

 

Is there a way around this?

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.