Forums

Variable URL in redirect action

enzo.orsi 28 Jan, 2016
Do you think that is possible to have a variable URL for redirect action?
...without using custom code...
GreyHead 29 Jan, 2016
Answer
2 Likes
Hi enzo-orsi,

Officially, no, but if you don't mind a little bit of work yes you can over-write the url using a Custom Code action before the ReDirect. Here's my test code:
<?php
if ( !empty($form->data['radio1'] ) ) {
  $url = 'http://'.$form->data['radio1'];
  $form->actions_config[3]['url'] = $url;
}
?>
The important line is the $form->actions line. you need to replace the 3 there with the action ID of the ReDirect action 0 it's the number that shows up in the Setup Tab.

Your code needs to make sure that what you set is a valid URL!

Bob
enzo.orsi 29 Jan, 2016
Thank you very much Bob!
It is great.
Just two hints:

- I added a random URL in Redirect URL field in the event, otherwise I had error in the CF dashboard (because URL cannot be empty)
- I did something similar also for PayPal Redirect:

$url_paypal_redirect = JUri::root() . 'index.php?option=com_chronoforms5&chronoform=MYFORM&event=ipn';
$form->actions_config[xxx]['return'] = $url_paypal_redirect ;

where 'xxx' is the ID of PayPal Redirect event.
GreyHead 29 Jan, 2016
Hi enzo.orsi,

Yes, it make sense to put a default URL In the box to hide the 'error' report.

While you can do this with the PayPal Redirect you don't need to as the root URL stays the same and you can set the variable parameters in the Extra Params box.

Bob
This topic is locked and no more replies can be posted.