Page 1 of 1

Help with changing form action dynamically

Posted: Thu Oct 11, 2012 5:49 pm
by phpleaner11
Hi,

I am new to php coding and I am trying to do a small change to an existing piece of code. I am unable to figure out the way to do it.

Problem statement : based on the get variable (received from wordpress form); I need to change the form action of the php file.

if $_GET["topic1"] = "abc" then user has to be redirected to page - http://ourdomain.com/thankyou/\" after information processing; else if $_GET["topic1"] != "abc" then the form action should be 'https://secure.url.net/folder/web/index.jsp'

*************** Existing code **************
<html>
<body onLoad="document.tpgpayment.submit()">
<form id = 'myform' name= 'myform' action='https://secure.url.net/folder/web/index.jsp' method = 'post'>
<?
include '/var/www/config/dbconfig.php';
$tPassData = "";
$i = 0;

<--- business logic written in php -->
?>
</form>
</html>
************** End of Code *******************

Any ideas or suggestions will be of a great help.

Thanks!
phpLearner

Re: Help with changing form action dynamically

Posted: Thu Oct 11, 2012 6:26 pm
by requinix
You can't post a form to one place and send the user somewhere else instead. Does that url.net thing allow you to redirect people back? Give the user a link to click?

Re: Help with changing form action dynamically

Posted: Fri Oct 12, 2012 10:53 am
by phpleaner11
What we are handling is a registration form. As the user complete the registration form, they are redirected to payment system (...//secure.url.net/folder/web/index.jsp)....After payment is done on the external site, the user is returned back to our side to a thank you page (...//ourdomain.com/thankyou/). Now the requirement is, if user register for the new session thats opened (which is free for users). User must not be routed to payment system (as there is none); instead should be sent to the thankyou screen directly. This code is written way back by another developer and need to be changed now for this specific requirement. we cannot give a user link to select.

Re: Help with changing form action dynamically

Posted: Fri Oct 12, 2012 12:35 pm
by requinix
All you need to do is decide what action the form should submit to, which sounds obvious but I mean to do that in code. Like

Code: Select all

if it's this new session thing {
    action = your thank you page
} else {
    action = payment vendor's page
}
and then use that URL in the form's action (rather than hardcoding it like it is now).