Form Method="Get" Problem

Status
Not open for further replies.

DonDadda

New member
Feb 6, 2008
214
0
0
Hey heads,

I wanted to know if anyone could help me with this coding problem, I am using the form method="get" to send a number and to answer a "yes" or "no" type question using radio buttons.

What I want to be able to do is when a user selects "no" instead of being sent to the link specified in the form method="get" they will be sent to another link along with the number the user entered.

Anybody know how to do this? Much appreciation.
 


Page1.php=Your yes or no question. Submits to page2.php
PHP:
<?php 
$res=$_GET['answer'];
if($res=="yes")
{
header("Location: http://www.site1.com");
}
else
{
header("Location: http://www.site2.com");
}
?>

Assuming your value for the "Yes" radio button is "yes" and it's name is answer.
 
in perl

Code:
#!/usr/bin/perl
use CGI qw/:cgi-lib/;
%FORM=Vars();

$location1="http://www.site1.com";
$location2="http://www.site2.com";

if($FORM{'answer'} eq "yes") {
     print "Location: $location1\n\n";
}
else {
     print "Location: $location2\n\n";
}
 
Teach the guy switch()

uhhhhg. There's one in every crowd. No respect for a good ol' fashioned binary option :D

Perl with switch

Code:
#!/usr/bin/perl
use CGI qw/:cgi-lib/;
%FORM=Vars();

$location1="http://www.site1.com";
$location2="http://www.site2.com";

use Switch;

switch ($FORM{'answer'}) {
    case "yes" {
         print "Location: $location1\n\n";
    }
    case "no" {
         print "Location: $location2\n\n";
    }
}
 
Hey thanks for the help, I can get it to change links when yes or no is selected, however I can't get it to pass the variables to send the "number" and the "yes" selection. Any suggestions?
 
Nah the html works, I just can't get it to pass the "Yes" variable from mysite.com to mysite.com/page2 to site1.com. I can get the "Age" variable to pass though. All I need is for that damn "Yes" varaible to pass then I'm in business. Here is the code on mysite.com
--------------------------------------------------------------------------
<form method="get" action="http://www.mysite.com/page2.php" form name="retard" onsubmit="document.getElementById('start').innerHTML='Please Wait'">

1.Enter your age?

<input name="age" class="form" type="text" size="3" maxlength="3"/>

2.Are you retarded?

<input type="radio" input name="retard" value="Yes" checked>
Yes
<input type="radio" name="retard" value="No">
No
<div id="message"><input type="image" src="/images/gobutton.gif" name="start" value='Submit'/>

</form>
-------------------------------------------------------------------------------

Here is the code on mysite.com/page2.php

-------------------------------------------------------------------------------

<?php
$res=$_GET['retard'];
if($res=="Yes")
{
header("Location: http://www.site1.com");
}
else
{
header("Location: http://www.site2.com");
}
?>
 
i just created a html file with your code in it. It worked fine for me. This was the get method output

http://www.mysite.com/page2.php?age=12&retard=Yes&start.x=&start.y=&start=Submit

Also make sure there's no space between .innerHT ML
<form method="get" action="http://www.mysite.com/page2.php" form name="retard" onsubmit="document.getElementById('start').innerHT ML='Please Wait'">

also point of interest
<input type="radio" input name="retard" value="Yes" checked>
Yes
 
Switch is for programmers who want to be unique, and therefore rebel against if()

switch is for those with too many radio buttons. Besides, you know me better. I have indians who are unique:Yahoo_29:

Side note - why is there a smiley on a cross and no smiley on a magen david? Jon?
 
Switch is for programmers who want to be unique, and therefore rebel against if()

Sorry in advanced for being boring but there is actually a huge difference hardware wise between an if conditional and a case. In fact it uses totally different hardware. I honestly don't know how the scenario plays out with various compilers and interpreters but the easiest way to show the difference at least on a PLD structure (programmable microchip) is like this:

if ($var1 == "something) {
do this
}
elsif ($var2 == "something") {
do that
}

if the if is true than only the "do this" would happen. It wouldn't matter what the else if was.

case ($var1 == "something") {
do this
}
case ($var2 == "something") {
do that
}

if both conditions are true than both the "do this" and the "do that" would be fetched at the exact same time and both would be done.

Even with two if statements.
if ($var1 == "something) {
do this
}
if ($var2 == "something) {
do that
}

In this instance both would be done, the "do this" and the "do that." However the "do this" would be done first thus the "do that" could possibly result in a different outcome if it's data is dependent on the "do this." So with that basic understanding in this instance, where both cases can result in a possible true, using a switch would be a bad idea and could result in whats known as a data dependency error or an even worse data contention error.
I hope that sorta made sense :)
 
Last edited:
Meh, you're doing something wrong if you're not trying to implement Duff's Device at every opportunity: Duff& - Wikipedia, the free encyclopedia

how to do that in php? do a c extension that implements the fucking algo? why don't you just go ahead and code that in assembly or even machine language.. just get the job done, fast:

<?php
header("Location: " . $_GET['retard'] == "Yes" ? "http://www.site1.com" : "http://www.site2.com");
?>
 
how to do that in php? do a c extension that implements the fucking algo? why don't you just go ahead and code that in assembly or even machine language.. just get the job done, fast:

<?php
header("Location: " . $_GET['bummer'] == "Yes" ? "http://www.site1.com" : "http://www.site2.com");
?>

Fuck me: you're taking my post seriously?
 
how to do that in php? do a c extension that implements the fucking algo? why don't you just go ahead and code that in assembly or even machine language.. just get the job done, fast:

<?php
header("Location: " . $_GET['retard'] == "Yes" ? "http://www.site1.com" : "http://www.site2.com");
?>

Before you insult someone with php code, it would be awesome if yours actually worked.
 
Status
Not open for further replies.