Forum Moderators: coopster
I want to compare apples, oranges, bananas, grapes and pears. Each option would have a checkbox.
When someone checks apples, oranges and bananas, they'd be taken to static page comp_aob.html, when someone checks apples and bananas, they'd be taken to comp_ab.html.
Could someone help me get started? I'd like this to be as simple as possible but I have no idea where to start.
Thanks!
<?php
if(isset($_POST['fruit'])) {
$num = array('o','a','b','g','p');
$count = count($_POST['fruit']);
$url = 'comp_';
for($i = 0; $i < $count; $i++) {
$url .= $num[$_POST['fruit'][$i]];
}
$url .= '.html';
echo $url;
}
?>
<br/><br/>
<form action="index.php" method="post">
Orange<input type="checkbox" name="fruit[]" value="0" /><br />
Apple<input type="checkbox" name="fruit[]" value="1" /><br />
Banana<input type="checkbox" name="fruit[]" value="2" /><br />
Grape<input type="checkbox" name="fruit[]" value="3" /><br/>
Pear<input type="checkbox" name="fruit[]" value="4" /><br />
<input type="submit" value="Click me!" />
</form>
One problem with this is that if you do not have the check boxes in the correct order, the page's url will be wrong.
Best of luck!
That way you don't have to pull the letter from the array.
tsk tsk tsk...I'm getting worse every day ;)
instead of using for loop (which I dislike) you can:
<?php
if(isset($_POST['fruit'])) {
$fruits = $_POST['fruit'];
sort($fruits);
$url = 'comp_'.implode("", $fruits).'html';
echo $url;
}?>
<br/><br/>
<form action="index.php" method="post">
Orange<input type="checkbox" name="fruit[]" value="o" /><br />
Apple<input type="checkbox" name="fruit[]" value="a" /><br />
Banana<input type="checkbox" name="fruit[]" value="b" /><br />
Grape<input type="checkbox" name="fruit[]" value="g" /><br/>
Pear<input type="checkbox" name="fruit[]" value="p" /><br />
<input type="submit" value="Click me!" />
</form>
We are all getting older Eelix
Regards HairyCoo
Michal
implode is the best solution in this case, but I first used the loop because I wasn't thinking and taking the values from an array. Anyway, your solution is better :)
>>>We are all getting older Eelix
haha...yup...Except I haven't even passed 20 yet ;)
P.S. Nice idea with the sort.