www.webdeveloper.com
Results 1 to 5 of 5

Thread: Setting <form action= a variable

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    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">
    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>');
    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">');
    I don't want to make 100000 if statements though! Any help would be AWESOME!

    Thanks
    Vex

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    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:
    PHP Code:
    function auaComp($v1$v2){
        return (
    $v1 != $v2) ? 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 .'">'); 

  3. #3
    Join Date
    Oct 2011
    Posts
    3
    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
    PHP Code:
    $data "s1="."$s1";
    echo(
    '<form method="get" action="tictactoe.php?data="."$data"" >'); 
    $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.

  4. #4
    Join Date
    Aug 2008
    Location
    Phoenix, AZ
    Posts
    84
    It looks like you have your quotes in the wrong place. Try doing it this way instead.:
    PHP Code:
    $data 's1=' $s1;
    echo 
    '<form method="get" action="tictactoe.php?data=" '$data '" >'
    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?

    Quote Originally Posted by vexstorm View Post
    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
    PHP Code:
    $data "s1="."$s1";
    echo(
    '<form method="get" action="tictactoe.php?data="."$data"" >'); 
    $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.
    Keep your nose to the grindstone, it sharpens your boogers.

  5. #5
    Join Date
    Oct 2011
    Posts
    3
    I got it figured out! Thanks alot guys.. beau kang you were right. I was messing up my quotes alot. :P.. I fixed it and it works perfectly! Here is what I did..

    PHP Code:
                $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>'); 
    Thanks again!! ^__^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles