Forums

Go To Page Based On Checkbox or Radio Button Using Event Switcher

melvins138 04 Sep, 2014
I have been reading numerous forum posts about the Event Switcher [GH], but I am still confused on how to handle this.

Using CFV4 on Joomla 3.1.5.

I have a five page sign up form. On the first page, I have two checkboxes (I can switch to radio boxes if that makes it easier) that asks if you are inside the sign up period or outside the signup period.

If you select that you are INSIDE the signup period, the page flow would be:
Page 1 > Page 3 > Page 4 > Page 5

If you select that you are OUTSIDE the signup period, the page flow would be:
Page 1 > Page 2 > Page 3 > Page 4 > Page 5

So basically, you would choose which checkbox (or radio button), click a "Next Page" submit button, then head to the correct following page in the form.

Can someone give me a quick tutorial on how to do this?

Thanks,
Melvins138
GreyHead 04 Sep, 2014
Hi Melvins,

What code do you have in the Event Switcher [GH]?

I would probably set it up so that the normal flow was Page 1 > Page 2 and then use one of the Event Switcher events to send the 'Inside' Users directly to Page 3 - I think that a Show Form action will do that for you.

Bob
melvins138 04 Sep, 2014
Answer
I should have trusted myself a little better.

I followed the instructions from "Problem 1" on this forum post to create the right script.

I then set up three pages.

Page 1) Radio Box and Submit Button.
I make a radio box with two options 1) Inside (GoTo Page 3) and 2) Outside (GoTo Page 2). Gave them a value of 2 and 1 respectively. I gave the radio box a name and ID of "broker"

In Events, added "Multi Page" and "Show HTML" actions. Set "Show HTML" submission event to "PageTwo" with the Page Number set to 1.

Page 2) Check Box and Submit Button.

In Events, set Events Switcher [GH] action with this code

<?php
  $jinput = JFactory::getApplication()->input;
  $broker = $jinput->getString('broker', '', 'post');

  if ($broker == '1') {
    return 'event_a';
  } else {
    return 'event_b';
  }
?>


Added a "Show html" action to Event A, set Submission Event to "PageThree" and gave it a Page Number of 2

Added a "Show html" action to Event B, set Submission Event to "submit" and gave it a Page Number of 3


Page 3 ) Welcome to Page Three Text and Submit Button

In Events, added a "Show html" action, set Submission Event to "submit" and gave it a Page Number of 3

Boom! Worked exactly as I needed it to. When you click "Outside" you go to page 2, then from page 2 you submit to page 3. When you click "Inside" you go to page 3.
melvins138 04 Sep, 2014
If there is a better way for me to write the Event Switcher code, please let me know.
GreyHead 04 Sep, 2014
Hi Melvins 138,

What's there is fine, you can tidy it up a bit because ChronoForms automaticlaly adds the URL query parameters to the $form->data array. So this
<?php
  $jinput = JFactory::getApplication()->input;
  $broker = $jinput->getString('broker', '', 'post');

  if ($broker == '1') {
. . .
could be replaced with
<?php
if ( isset($form->data['broker']) && $form->data['broker'] == '1' ) {
. . .
I added the isset() part just to prevent a possible error if broker isn't in the query string. You might need some other code to handle that case.

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