Forums

Conditional Redirect

joey 32660667 25 Sep, 2011
Joomla! 1.7.0
ChronoForms 4.0 RC2.0

I'm building a signup process which will require the user to complete a different form depending on which option they sign up for. There are five options, and each one requires a different set of information to be submitted.

I have one extremely simple form (Step 1) consisting of five radio buttons; if a user selects Button 1, I need them to be redirected to the appropriate form (Form 1), Form 2 for Button 2, and so on. So far, I have tried to make this work by inserting some custom code (which I think I found on this forum, written by Bob) into the On Submit Event. Here's what I have currently:

<?php
  if (isset($_POST['chooseplan_input_radio_0'])=="Silver") {
      echo ('Silver');
  } elseif (isset($_POST['chooseplan_input_radio_0'])=="Mobile") {
     echo ('Mobile');
  } elseif (isset($_POST['chooseplan_input_radio_0'])=="Gold") {
    echo ('Gold');
  } elseif (isset($_POST['chooseplan_input_radio_0'])=="Platinum") {
    echo ('Platinum');
  } elseif (isset($_POST['chooseplan_input_radio_0'])=="Create A Custom Plan") {
    echo ('Custom');
  }
?>


Obviously, all this is supposed to do right now is echo back which plan was selected, but it just says "Silver" regardless of which button I choose. I have some experience with PHP, mostly hacking on others' components, but am not skilled enough to write my own functions. I'm very well-versed in Joomla! and basic markup. Any help or pointers would be greatly appreciated!
a.carter 26 Sep, 2011
Hello Joey,

I achieved this in a form I did recently using the following code in the "On Submit code - after sending email" box:


<?php

if ($_POST['radio5'] == 'No') {
	$mainframe->redirect('/thankyou.html');
}
?>


The form HTML for that radio button group (radio5) was:

      <input value="Yes" title="" class="radio validate-one-required" id="radio40" name="radio5" type="radio" />
      <label for="radio40" class="radio_label">Yes</label>
      <input value="No" title="" class="radio validate-one-required" id="radio41" name="radio5" type="radio" />
      <label for="radio41" class="radio_label">No</label>


I didnt use isset as i have validation on that radio button so it will always be set.

Make sure that your html tag "value" (see the <input value="No".... tag in my form HTML?) matches the value your writing in your if statement. In my case, it was "No" (case-sensitive).

Hope this helps you further.
GreyHead 26 Sep, 2011
Hi Joey,

Your PHP has gone a bit wonky so the test you are using is isset('xxx') == 'xxx' instead of 'xxx' == 'xxx', as isset returns true or false it's not giving you the answer you expect.

In ChronoForms v4 I'd write this:
<?php
if isset($form->data['chooseplan_input_radio_0']) ) {
  echo $form->data['chooseplan_input_radio_0'];
} else {
  echo 'Nothing found';
}
?>
or
<?php
if isset($form->data['chooseplan_input_radio_0']) ) {
  switch $form->data['chooseplan_input_radio_0'] {
    case 'gold':
     $url = 'gold_url';
     break;
    case 'silver':
     $url = 'silver_url';
     break;
     . . .
  }
} else {
  $url = 'some_other_url';
}
$mainframe =& JFactory::getApplication();
$mainframe->redirect($url);
?>

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