Changing the Action attribute of Form

This is a discussion on Changing the Action attribute of Form within the PHP General forums, part of the PHP Programming Forums category; I need to pass control of a form to either a page that accesses our database, and displays the data, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-01-2006
sues
 
Posts: n/a
Default Changing the Action attribute of Form

I need to pass control of a form to either a page that accesses our
database, and displays the data, OR to a page that contains static content.
The ACTION attribute will then depend on the contents of 1 of the input
fields in the form, which is a SELECT type of input. Here is an example of
what the form looks like:

<form id="test" action="some_page.php" method="get" name="test">
<select name="test_item" size="1">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>

If "Item 1" is selected, I want to go to a certain page (some_page.php), and
if "Item 2" is selected I want to go to a different page. Is there a way to
handle this using PHP or JavaScript? Any help would be greatly appreciated!

Thanks!
Reply With Quote
  #2 (permalink)  
Old 11-01-2006
João Cândido de Souza Neto
 
Posts: n/a
Default Re: Changing the Action attribute of Form

<scipt language="javascript">
function change_action(obj) {
if (obj.test_item.value="1") obj.action="page_1.php";
if (obj.test_item.value="2") obj.action="page_2.php";
return true;
}
</script>
<form name="test" action="some_page.php" method="get" name="test">
<select name="test_item" size="1" onchange="return
change_action(document.teste);">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>


""sues"" <skot1@twcny.rr.com> escreveu na mensagem
news:02.4E.30579.92BB8454@pb1.pair.com...
>I need to pass control of a form to either a page that accesses our
>database, and displays the data, OR to a page that contains static content.
>The ACTION attribute will then depend on the contents of 1 of the input
>fields in the form, which is a SELECT type of input. Here is an example of
>what the form looks like:
>
> <form id="test" action="some_page.php" method="get" name="test">
> <select name="test_item" size="1">
> <option value="1">Item 1</option>
> <option value="2">Item 2</option>
> </select>
> <input type="submit" name="submit" value="submit" />
> </form>
>
> If "Item 1" is selected, I want to go to a certain page (some_page.php),
> and if "Item 2" is selected I want to go to a different page. Is there a
> way to handle this using PHP or JavaScript? Any help would be greatly
> appreciated!
>
> Thanks!

Reply With Quote
  #3 (permalink)  
Old 11-01-2006
Ed Lazor
 
Posts: n/a
Default Re: [PHP] Changing the Action attribute of Form

> javascript: Have the submit button call a JS function which would
> check the state of the select and set the action appropriately
> before submitting the form.
>
> PHP: submit the result to a dispatcher script that'll redirect to
> one of the targets based on what has arrived in the data (you'll
> lose the ability to POST though).


I'd chose the javascript route personally. You could use PHP's curl
functions to rePOST the data, but that seems like more work than is
necessary.

My .02 cents. :)

-Ed
Reply With Quote
  #4 (permalink)  
Old 11-01-2006
David Giragosian
 
Posts: n/a
Default Re: [PHP] Changing the Action attribute of Form

Wasn't there a thread recently about a webpage having multiple forms on it,
each of course with its own action attribute? Might be another solution
here.

David


On 11/1/06, Dave Goodchild <buddhamagnet@gmail.com> wrote:
>
> Example HTTP redirect:
>
> header('Location: http://www.google.com");
>
>


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:01 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0