Convert HTML post to URL string

Discussion in 'Programming' started by WoodiE55, Jul 20, 2012.

  1. #1
    I have a form html code that uses POST to submit data to a server. What I'm trying to do is get the URL string that would essentially submit the same data, but without having to use the form.

    How would I do this?

    
    <form method='post' action='gym.php'>
    <table class='customtable2'>
        <tr>
            <td><b>Strength</b></td>
            <td><input type='text' size='5' value='0' name='str' id='strength_q' /></td>
    
            <td colspan='2' align='center'></td>
        </tr>
        <tr>
            <td><b>Defense</b></td>
            <td><input type='text' size='5' value='0' name='def' id='defense_q' /></td>
            <td colspan='2' align='center'></td>
        </tr>
        <tr>
            <td><b>Speed</b></td>
            <td><input type='text' size='5' value='100%' name='spd' id='speed_q' /></td>
            <td align='center'><button class='button small brown' type='button' onclick="$('#strength_q').val('33%');$('#defense_q').val('33%');$('#speed_q').val('33%');"><span>Split</span></button></td>
            <td align='center'><button class='button small' type='submit'><span>Train</span></button></td>
        </tr>
    </table>
    </form>
    
    Code (markup):
     
    WoodiE55, Jul 20, 2012 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    If you want to use post, you have to use an HTTP post request either through a form or wih PHP's cURL. I think what you need is a get request ($_GET) which passes data via variables within the url, for example:

    On the HTML side:

    
    <a href="www.mysever.com/index.php?strength=8&speed=10&defense=5" title="Click to send">Send to server</a>
    
    Code (markup):
    Then on the server side use $_GET array to retrieve the values, like so:

    
    if(!empty($_GET))
    {
        if(array_key_exists("strength", $_GET))
        {
            $strength = $_GET["strength"];
        }
    }
    
    Code (markup):
    I also recommend you don't use HTML tables, they're terribly outdated so use CSS.
     
    Last edited: Jul 21, 2012
    BRUm, Jul 21, 2012 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    as BRUM said, you'd need to use GET instead of POST -- the entire reason to use POST is so that it isn't passed through the URL! That's what POST is for.

    ... and yeah, lose the tables -- and while at it lose the B tag's doing LABEL's job, the empty colspans doing padding or margin's job... basically throw 50% of that markup in the trash :D
     
    deathshadow, Jul 21, 2012 IP