PDA

View Full Version : Setting a variable outside the POST function


Matrix
03-11-2003, 10:35 AM
Hi All - it's an odd title, I know ... let me explain:

I have a page ("order.php") with a form that POSTs a whole bunch of values to a PHP page ("page1.php"), which works fine.

BUT I now want to be able to click a button from within the form on order.php, display a different page ("page2.php") and set the value of a variable in that page.

I know that might look like a php question, but I'm pretty sure this part can be done with JS ... I'm just not sure if I can open the new page first and then set a hidden variable in that page.

Does anyone have a little workaround for this? Or am I looking at the problem from the wrong side?

My only other thought was to try a form within a form, use PHP and POST the "inner form" to the new page taking the variable value to the new page, but I've never heard of this and don't know what impacts it might have.

[if it helps to explain ... i've got a product order form that posts to a confirmation and payment page; I now have products in the order form that are a special order and need to be quoted on. So there is a new "special order inquiry" page/form on which I want to display the name of the item being inquired on. SO - all i want to do is set a variable in the new page from within the order page. Make sense? I hope so!]

Any suggestions would be appreciated!

Cheers guys,
Matrix.

Roy Sinclair
03-11-2003, 03:36 PM
<form action="notsetyet.php">
...
<input type="submit" value="Submit to Page 1" onclick="this.form.action='page1.php'; return true;">
<input type="submit" value="Submit to Page 2" onclick="this.form.action='page2.php'; return true;">
...
</form>


Is this what you want?

Matrix
03-11-2003, 10:11 PM
Hi Roy -

Thanks for that ... I'll give it a go, but I think that in order to carry the variable value across to page2.php I actually have to "POST" or "GET" the page. The page1.php action is done via a submit action tied to the form, of course, but I'm not sure if just calling page2.php will send the values across. As I said though ... I'll give it a go & see what happens.

Many thanks for your response!

M.

Jason
03-11-2003, 10:42 PM
if you are trying to do it with a JS you will want to use a parent child script. Otherwise you can possibly pass variables through the URL using PHP with www.mywebpage.com?newValue=$value&secondValue=$value2 and so on. But if you are using JS I suggest a search on the parent child relationship cause Im sure you will find alot.


Jason

Matrix
03-11-2003, 10:52 PM
Hi Jason - many thanks for your suggestion ... I will review the various help files available and see if I can work out a more elegant solution, as you suggest.

With regard to the snippet you wrote below ... I have always just assumed that the variables are passed via the URL as a consequence of submitting a form ... never occurred to me to hardcode a variable to pass (pretty obvious now I think about it of course!). That may actually be easier for me - especially since it's "one button, one value". I have three of these buttons at the moment that call the page2.php page from within the form, and onBlur calls a JS to set a hidden field value to the relevant product name. So, I could just set the buttons as Roy noted above, but include the variable directly in the page call, as you've suggested.

I'll give that a go first I think, but will also look up the parent/child facility.

My sincere thanks again,
M.