I would like to have several buttons, each will post data to a different URL but I cant figure out how to code the "<form action=" to accept a different URL depending on which button is pressed. I have tried stuff like:
<form name='out' method='post' action="<? echo $page_name; ?>"> but it cant pass it back in retrospect.
I can see if you are prepared to reload the form it can be done but this is clearly too clumsy.
I dont want to embed javascript as I am trying to make the transition to PHP!
Will some one point me in the right direction please.
Thanks
Multiple Actions
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Why not post everything to one page, detect which button was pressed there and using a switch statement include a file with the coding for dealing with the information based on the button pressed?
Otherwise you are going to have to reload the form or use javascript to create the action attribute's value each time.
Because javascript is client-side and PHP is server-side they do not really replace each other as each can do things the other can't.
Mac
Otherwise you are going to have to reload the form or use javascript to create the action attribute's value each time.
Because javascript is client-side and PHP is server-side they do not really replace each other as each can do things the other can't.
Mac
Code: Select all
<form name='out' method='post' action="<? echo $page_name; ?>">Code: Select all
<?php
echo "<form name='out' method='post' action='$page_name' />";
?>of course you can't.but it cant pass it back in retrospect.
I suppose a little misunderstanding.
Code: Select all
<form name='out' method='post' action="<? echo $page_name; ?>">Code: Select all
<form name='out' method='post' action="target.php">Code: Select all
<html><head><script language="JavaScript">
function submit_form(oForm, sUrl)
{
oForm.action = sUrl;
oForm.submit();
}
</script></head><body>
<form action="" method="GET">
<input type="text" name="myContent"/><br/>
<button onClick="submit_form(this.parentElement, 'page1.php')">page 1</button><br/>
<button onClick="submit_form(this.parentElement, 'page2.php')">page 2</button><br/>
<button onClick="submit_form(this.parentElement, 'page3.php')">page 3</button><br/>
</form>
</body></html>