Click to See Complete Forum and Search --> : Form input to URL


jrthor2
05-22-2003, 09:56 AM
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?

pyro
05-22-2003, 10:00 AM
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:

$first = $_GET['var1']; //will equal firstvalue
$second = $_GET['var2']; // will equal secondvalue

jrthor2
05-22-2003, 10:11 AM
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>

pyro
05-22-2003, 10:13 AM
The forms method should be GET rather than POST, then.

jrthor2
05-22-2003, 10:19 AM
Oops, my bad. But i am gettig a parse error on the line that has my form action???

pyro
05-22-2003, 10:24 AM
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...

jrthor2
05-22-2003, 10:28 AM
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?

pyro
05-22-2003, 10:37 AM
Using the GET method of a form, that is how they are passed.

jrthor2
05-22-2003, 10:42 AM
ok, gotcha, so that's the difference between Get and Post.

Thanks

pyro
05-22-2003, 10:44 AM
Yes, and, POST is recommended for most situations, as the information isn't passed via the addressbar. POST is more secure.

bluehaley
09-06-2003, 01:20 PM
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.

pyro
09-06-2003, 05:04 PM
You're server probably doesn't support golbar variables. Read all about it (http://www.webdevfaqs.com/php.php#globalvariables) ...

bluehaley
09-06-2003, 09:10 PM
Thank you Pyro. The link helped and $_POST('ssn') worked.

pyro
09-07-2003, 12:11 AM
You bet... glad the link helped you out. But, you mean $_POST['ssn'] right? ;)