I’m working on integrating a payment solution for a client, and the payment processor requires the value of 2 of the mandatory form fields to be inaccessible via view > source. I’ve cooked up an elaborate scheme in which the initial page is a form that doesn’t contain the 2 fields, just the basic customer info (name, contact, donation amount). The submit action posts to a form handler that:
[list=1][]Using a PHP Include, connects to a database to retrieve the ‘protected’ form values, specified by the primary key
[]Fetches an array containing the 2 values (using a while loop)
[]Posts the info from the 1st form
[]Builds a new form containing the info from the 1st form, to which the 2 required fields are appended, but with empty values
[]The PHP Include then prints a link to a .js file
[]JS inserts the variables (specified in the PHP Include) in the form values
[]The PHP Include is supposed to read the 2 variables and replace them with the output of the fetched array
[]A JS onLoad would then submit the form to the payment processor[/list]
Other measures are also in place to keep the casual looker from seeing the output, but the main mechanism relies on this: if JavaScript is enabled, the 2nd form (the one with the goodies) submits before you have a chance to inspect the output or source code, or use a developer browser plugin to view it. If JavaScript is disabled, the variables never get inserted, thus the PHP doesn’t write the output in the form values.
The problem is, once the JS inserts the variables, the PHP include has already run, and doesn’t replace the variables with the data from the fetched array.
So question 1 is, how to get that working? I’ve tried breaking out the while loop and inserting it after the JavaScript; removing the JS document.ready, etc. but nothing seems to work.
Question 2 is, does PHP have a way to determine if the requesting browser has JavaScript disabled, so I could write something like:
if (!JavaScript){
exit;
}
else {
$includeJS = '<script type="text/javascript" src="path/to/include.js"></script>';
}
And of course, if you know a better way to protect form values, I want to hear it.
Thanks,