www.webdeveloper.com
Results 1 to 14 of 14

Thread: Form input to URL

  1. #1
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898

    Form input to URL

    Is there a way to take the data from a form and when you hit submit, put that data in the url of the page you are submitting to? I am trying to get data from 2 different databases to compare the data and here at work we have a program called Actuate that is going to do the backend stuff and the person in charge of that program said I could use any language to write my page as long as I can send the variables in the url. Is this possible?

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, you can send variables in the URL via the query string in PHP. You can then parse them off using either $_SERVER['QUERY_STRING'] or $_GET['varname']. So, if you send this: yourpage.php?var1=firstvalue&var2=secondvalue, you can get the values like this:

    PHP Code:
    $first $_GET['var1']; //will equal firstvalue
    $second $_GET['var2']; // will equal secondvalue 

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Hmm, here is my code, maybe I'm not asking right. When I sumbit my page, the url it posts to has to have the variables in it. here is my form code.

    <form method="post" action="table_search_results.php?table=<? = $_GET['table'] ?>&cust_nbr=<? = $_GET['cust_nbr'] ?>&pkgid=<? = $_GET['pkgid'] ?>">
    <table width="53%" border="0" cellspacing="0" cellpadding="5">
    <tr valign="top">
    <td>Table:</td>
    <td><select name="table" id="table">
    <option value="PNCST_CUSTOMER" <?if($table=="PNCST") { echo " selected";} ?>>PNCST</option>
    </select></td>
    </tr>
    <tr valign="top">
    <td width="47%">Customer Number:</td>
    <td width="53%"><input name="cust_nbr" type="text" id="cust_nbr3" size="9" maxlength="9" value="<? echo $cust_nbr ?>">
    </td>
    </tr>
    <tr valign="top">
    <td>Package ID:</td>
    <td><input name="pkgid" type="text" id="pkgid" size="6" maxlength="9" value="<? echo $pkgid ?>"></td>
    </tr>
    <tr>
    <td colspan="2" valign="top"><p align="center">
    <input type="submit" name="Submit" value="Compare">
    <input type="hidden" name="submit" value="1">
    </p></td>
    </tr>
    </table>
    </form>

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    The forms method should be GET rather than POST, then.

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Oops, my bad. But i am gettig a parse error on the line that has my form action???

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Your action should not be action="table_search_results.php?table=<? = $_GET['table'] ?>&cust_nbr=<? = $_GET['cust_nbr'] ?>&pkgid=<? = $_GET['pkgid'] ?>" but rather action="table_search_results.php" and then include the variables you were trying to add in as hidden fields. ie. <input type="hidden" name="table" value="<?PHP echo $_GET['table']; ?>"> etc...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  7. #7
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    yes, but then how do I pass the url with these variables to this Actuate program? The person in charge of Actuate said the variables need to be passed in the url?

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Using the GET method of a form, that is how they are passed.

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  9. #9
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    ok, gotcha, so that's the difference between Get and Post.

    Thanks

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, and, POST is recommended for most situations, as the information isn't passed via the addressbar. POST is more secure.

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  11. #11
    Join Date
    Aug 2003
    Posts
    5

    Question how to get data when method=post?

    If I need to use form method post, how do I get the data?

    For example:
    <form method="post" action="<?php echo $PHP_SELF ?>">
    <input type="Text" name="ssn">
    </form>

    Can I simply use $ssn to get the value? Doesn't seem to work... Thanks.

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You're server probably doesn't support golbar variables. Read all about it ...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  13. #13
    Join Date
    Aug 2003
    Posts
    5
    Thank you Pyro. The link helped and $_POST('ssn') worked.

  14. #14
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You bet... glad the link helped you out. But, you mean $_POST['ssn'] right?

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

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