Jump to content

Redirect to different url depending on values of 2 dropdowns


Kevin_Verhoeven

Recommended Posts

I'm building a form for an organisation that organises a workshop for teenagers. There is an option to bring one or both parents to the workshop. So for each parent, there's a dropbox to answer the question "Will you participate in the workshop as well?" Depending if one, both or no parents will join, the user will be redirected to a different url after submiting (submit is always in the same place). The form is built with chronoforms in Joomla.

This is the code for the dropdowns, please note that I can't change the values "Ja" or "Nee" because these option values are also sent to an exterior, custom made program so i'm not allowed to change it. Code for the dropdowns:

 <select class="cf_inputbox validate-selection required" id="select_17" size="1" title="verplicht veld" name="oudersessieouder1" style="width: 193px;">
    <option value="">Make your choice</option>
<option value="Ja">Yes, will participate</option>
<option value="Nee">No, will not participate</option>
    </select><label class="cf_label" style="width: 150px;"> Will this parent join the workshop?</label>

<select class="cf_inputbox validate-selection required" id="select_18" size="1" title="verplicht veld" name="oudersessieouder2" style="width: 193px;">
    <option value="">Make your choice</option>
<option value="Ja">Yes, will participate</option>
<option value="Nee">No, will not participate</option>
    </select><label class="cf_label" style="width: 150px;"> Will this parent join the workshop?</label>

And this is the after submitting, here I can write the code to redirect depending on the values of the previous two dropdowns:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>bedankt</title>
</head>

<body>
<script>

if (one parent comes, so one of the 2 dropdown values will be "Ja")
window.location.replace("http://www.website.be/inschrijven-pe-jongeren-1-parent.html")
else if (both parents come, so both dropdown values will be "Ja")
window.location.replace("http://www.website.be/inschrijven-pe-jongeren-both-parents.html")
else
window.location="http://www.website.be/inschrijven-pe-jongeren.html"
</script>
<p align="center"> </p>
</body>
</html>
Link to comment
Share on other sites

So...are you just wondering how to test the values of your drop downs? Your select boxes are named "oudersessieouder1" and "oudersessieouder2".

 

The page that processes the drop downs would use $_POST or $_GET to access the information depending on what your <form> tag's method is set to. If it's set to POST, you can access the first select box with

$_POST['oudersessieouder1']

Note that you could use PHP's header() function to perform the redirects. More information can be found here:

http://php.net/manual/en/function.header.php

Link to comment
Share on other sites

  • 2 months later...

Based on the dropdown values, you want to redirect users to different page, right?

 

I consider you will button in the form. On clicking the button, call below function...

function redirect() {
   if(document.getElementById('select_17').value == 'Ja' && document.getElementById('select_18').value == 'Ja') {
     window.location.replace = 'both parents url';
   } else if(document.getElementById('select_17').value != 'Ja' && document.getElementById('select_18').value != 'Ja') {
     window.location.replace = 'both parents not coming url';
   } else {
     window.location.replace = 'one parents coming url';
   }
}
Link to comment
Share on other sites

Instead of oudersessieouder1 and oudersessieouder2

Just create an array by naming the select tags this:

 

<select name='oudersessieouder[]' ....>

 

Then you can just count how many values are in oudersessieouder

 

 

if( oudersessieouder1.length == 1 ) open 1 parent page
else if ( oudersessieouder1.length == 2) open 2 parent page
Link to comment
Share on other sites

Based on the OP I don't think he can change the select fields. I would go with a header() redirect as cyberRobot suggested.

 

 

<?php
 
$parentAttendees = 0;
 
//Determine how many parents will attend
if(isset($_POST['oudersessieouder1']) && $_POST['oudersessieouder1']=='Ja')
{
    $parentAttendees++;
}
if(isset($_POST['oudersessieouder2']) && $_POST['oudersessieouder2']=='Ja')
{
    $parentAttendees++;
}
 
//Determine the page to redirect to
if($parentAttendees==1) {
    //Redirect for one parent attendee
    $redirect = "pageForOneParentAttendees.php";
} elseif ($parentAttendees==2) {
    //Redirect for two parent attendees
    $redirect = "pageForTwoParentAttendees.php";
} else {
    //Redirect for No parent attendees
    $redirect = "pageForNoParentAttendees.php";
}
 
//Perform the redirecr
header("Location: {$redirect}");
exit();
 
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.