Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a forms action in PHP

Status
Not open for further replies.

rvr1

Programmer
Feb 6, 2004
16
NL
Hi,

I am quite new to PHP and wonder if someone could help me with the following problem.

I have a form which contains a drop down menu where the user can select two different values. What I would like to do is change the form action field depending upon which of these values is selected.

e.g. from:

<form action=&quot;Login.php?do=new&quot; method=&quot;post&quot;>

to:

<form action=&quot;Login.php?do=existing&quot; method=&quot;post&quot;>

Any help would be greatly appreciated.

Cheers,

Rob
 
This cannot be done in PHP.

A web browser connects to a URL of a PHP script. The web server runs the script, which produces HTML output. The web server streams the output to the browser. By the time the browser has rendered the page, the execution of the PHP script has already stopped.

In order to change the form's action, the PHP script would have to output JavaScript or VBScript code as a part of the HTML output. How to construct the JavaScript or VBScript is outside the realm of this forum.


There is a PHP way to handle this general class of problem, though. Instead of changing the destination to which the form submits the data, put two submit buttons on your form, the two with different names. When the form is submitted, the name of the particular submit button clicked will appear in PHP's input. Then a single script can perform one of multiple actions based on which submit button was clicked.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
the last answer is one way of doing it. but another is to have just a form that posts to another page and have a <input type=&quot;hidden&quot;... type of thing on the page that holds the &quot;do&quot; value. then on the next page you can check and see what the &quot;do&quot; value is at the top of the page.
or just change the &quot;do&quot; value on the page that this is being posted to depending on what selection was made.

David Kuhn
<a href=&quot; target=&quot;_blank&quot;>
 
Of course, if you want to use DHTML you can employ client side scripting such as JavaScript. That solution, however, has nothing to do with PHP. I'm sure the JavaScript forum will be of great help.
 
Could you not just always execute login.php and depending on the value passed in the drop doen make the decision within the script ?.
This is straight forward forms handling.
 
you could do it maybe use:
Code:
<form action=&quot;page.php?do=<?php echo($wotevr); ?>&quot;>

then above it you would need some switch thing, but you would have to make the page reload to make it in affect.

maybe some radio buttons?



Martin

Computing help and info:

[URL unfurl="true"]http://www.webrevolt.biz[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top