Form Action

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dajoker2505
    New Member
    • May 2010
    • 3

    Form Action

    i am somewhat new to php.

    Code:
    <?php
    
    echo"
    
    <span class='sif'>
    	<form method='post' action='index.php?username='>
    		Username <input type='text' name='username2'><br />
    		Password <input type='password' name='password2'><br />
    		<input class='sub' type='submit' value='Submit'>
    	</form>
    </span>
    
    
    ";
    i am trying to use GET in the action of the form with a variable that is not created until after the form submits.

    i want it to look like this. (change is in the action)

    Code:
    <form method='post' action='index.php?username=$TheirUsername'>
    Last edited by Atli; May 13 '10, 09:30 PM. Reason: Added [code] tags.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    how is the variable created then? Where is it coming from?

    What part are you having trouble with? i.e. what can't you do?




    Dan

    Comment

    • dajoker2505
      New Member
      • May 2010
      • 3

      #3
      i want to have their username or what they put into the form to be set in the action of the form so it sends them to a page index.php and i have a $_GET on another page (index.php) that will receive what their username by the ?username= in the URL.

      i am having trouble with how i would get a variable that isnt created until the form is complete to be inserted into the first part of the form.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hey.

        If you use the GET method instead of the POST method, your browser will automatically attach the variables to the URL. Although, considering that you are doing a login form, I would advice against that. All the fields will be added to the URL, not just the username, so the password will be (more) plainly visible.

        When you use the POST method, you use the $_POST array in PHP to fetch the data, not the $_GET array.

        If you really want to add the value of an input box to the form's action box before it is sent, you going to have to use JavaScript. PHP and HTML alone can't do that for you.

        Comment

        • dajoker2505
          New Member
          • May 2010
          • 3

          #5
          Originally posted by Atli
          Hey.

          If you use the GET method instead of the POST method, your browser will automatically attach the variables to the URL. Although, considering that you are doing a login form, I would advice against that. All the fields will be added to the URL, not just the username, so the password will be (more) plainly visible.

          When you use the POST method, you use the $_POST array in PHP to fetch the data, not the $_GET array.

          If you really want to add the value of an input box to the form's action box before it is sent, you going to have to use JavaScript. PHP and HTML alone can't do that for you.
          i didnt think i could. but i thought i would try. thanks for your time and the help

          Comment

          Working...