/    Sign up×
Community /Pin to ProfileBookmark

Setting <form action= a variable

Hey. I am new to this forum! I am learning php and school and having a bit of trouble doing what I want to do. I essentially want to take a set of variables and use them as my information for my

[code]<form method=”post” action=”tictactoe.php?s1=N&s2=N&s3=N”>[/code]

So this is what I have..

[code] if($_GET){
extract($_GET);

$data = “$s1″.”$s2”.”$s3″;

print(‘<form method=”post” action=$data>’);
print(‘<input type=”submit” id=”s1″ name=”s1″ value=”&nbsp; &nbsp;”/></form>’);
[/code]

All the $s values are being pulled from the url using $_GET and I want to put them into a string value and make it so if $s1=Y and all others are N it does..

[code]print(‘<form method=”post” action=”s1=Y&s2=N&s3=N”>’);[/code]

I don’t want to make 100000 if statements though! Any help would be AWESOME!

Thanks
Vex

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameOct 26.2011 — I would consider it bad idea to use extract() on $_GET (or $_POST) as it may potentially contain things you did not expect. You should know what variables to expect from $_GET and then only allow the script to use those expected variables. A simple way to do what you wish with some restriction of what is used via a pre-defined array of allowed $_GET key names, and query string creation via http_build_query:
[code=php]
function auaComp($v1, $v2){
return ($v1 != $v2) ? 0 : 1;
}
$allowedGETvars = array('s1' => '', "s2" => '', 's3' => '');
//if the items in $_GET which have the same key name as the
//items in $allowedGETvars do not have the same values as the
//items in $allowedGETvars, they will be returned in $data array
$data = array_uintersect_assoc($_GET, $allowedGETvars, "auaComp");
$urlVars = http_build_query($data, '', '&amp;');
print('<form method="post" action="tictactoe.php?'. $urlVars .'">');
[/code]
Copy linkTweet thisAlerts:
@vexstormauthorOct 26.2011 — Ya we talked about it in class but my teacher wants us to do it this way to learn how it works to understand better why not to use it.

I have this
[code=php]$data = "s1="."$s1";
echo('<form method="get" action="tictactoe.php?data="."$data"" >');[/code]


$data is "s1=Y" in this case.

When I click on the button it puts "tictactoe.php?s1=*+*" in my address bar

I want it to say "tictactoe.php?s1=Y"

Sorry for the confusion.
Copy linkTweet thisAlerts:
@beau_kangOct 26.2011 — It looks like you have your quotes in the wrong place. Try doing it this way instead.:
[code=php]$data = 's1=' . $s1;
echo '<form method="get" action="tictactoe.php?data=" '. $data . '" >';[/code]


As a rule, I think that it would be better to practice not putting your variables in quotes, especially if you are just learning how to use PHP. What editor are you using if I may ask?

Ya we talked about it in class but my teacher wants us to do it this way to learn how it works to understand better why not to use it.

I have this
[code=php]$data = "s1="."$s1";
echo('<form method="get" action="tictactoe.php?data="."$data"" >');[/code]


$data is "s1=Y" in this case.

When I click on the button it puts "tictactoe.php?s1=*+*" in my address bar

I want it to say "tictactoe.php?s1=Y"

Sorry for the confusion.[/QUOTE]
Copy linkTweet thisAlerts:
@vexstormauthorOct 27.2011 — I got it figured out! Thanks alot guys.. beau kang you were right. I was messing up my quotes alot. ?.. I fixed it and it works perfectly! Here is what I did..

[code=php] $data="s1=".$t."&s2=".$s2."&s3=".$s3."&s4=".$s4."&s5=".$s5."&s6=".$s6."&s7=".$s7."&s8=".$s8."&s9=".$s9."&t=".$ot."";
print('<form method="post" action="tictactoe.php?'.$data.'" >');
print('<input type="submit" id="s1" name="s1" value="&nbsp; &nbsp"/></form>');[/code]


Thanks again!! ^__^
×

Success!

Help @vexstorm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...