Help with changing form action dynamically

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpleaner11
Forum Newbie
Posts: 2
Joined: Thu Oct 11, 2012 5:47 pm

Help with changing form action dynamically

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with changing form action dynamically

Post 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?
phpleaner11
Forum Newbie
Posts: 2
Joined: Thu Oct 11, 2012 5:47 pm

Re: Help with changing form action dynamically

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with changing form action dynamically

Post 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).
Post Reply