Page 1 of 1

Text variable in url string

Posted: Sun Jan 31, 2010 8:28 am
by synical21
Hey Gurus,

I got a problem but I think im being dum about it. I want to send a custome message in the url to the next page E.G

process.php?jid=$job_id&jib=$createuser_id&tit=$title&cost=$cost&custom=$custom

The custom variable i need it to be a text box where a user can enter a sentence. The only way i know how to do this is a form i just want to know isit possible to send the message in the URL. Its the admin side of the site so it doesnt matter if the url is untidy.

Any help much appreciated.

Re: Text variable in url string

Posted: Sun Jan 31, 2010 9:38 am
by requinix
Yeah, it's possible. Anything in the URL can be accessed with $_GET.

Remember to urlencode whatever message you use.

Re: Text variable in url string

Posted: Sun Jan 31, 2010 9:52 am
by synical21
Ok now I know its possible how would I do it.

Normally i would just do $custom = "text here..."; but as it really has to be custom i dont know how it would work with a text box.

I thoguht it would be something like $custom = "<input name="custom" type="text" maxlength="60" value="text here">";

That doesn't look right to me, any suggestions on how i can input data to custom

Re: Text variable in url string

Posted: Sun Jan 31, 2010 10:11 am
by requinix
You don't have to use a form. A link is enough.

Code: Select all

$job_id = 123;
$createuser_id = 456;
$title = htmlentities(urlencode("Some title"));
$cost = 7.89;
$custom = htmlentities(urlencode("Custom message"));
echo "<a href='process.php?jid=$job_id&jib=$createuser_id&tit=$title&cost=$cost&custom=$custom'>Link</a>";

Re: Text variable in url string

Posted: Sun Jan 31, 2010 10:41 am
by synical21
The user needs to be able to create the custom message, which is why i thought text box. Sorry if that wasn't clear :oops:

Re: Text variable in url string

Posted: Sun Jan 31, 2010 11:52 am
by requinix
Then yes, use a form. Set the form method=get and pretend it's a posted form.

Code: Select all

<form action="process.php" method="get">
<input type="hidden" name="jid" value="$job_id">
<input type="hidden" name="jib" value="$createuser_id">
<input type="hidden" name="tit" value="$title">
<input type="hidden" name="cost" value="$cost">
<input type="text" name="custom" value="$custom">
<input type="submit" value="Submit">
</form>
The textbox will start with $custom but the user can change it if they want.

Re: Text variable in url string

Posted: Sun Jan 31, 2010 11:56 am
by synical21
Thanks you tasairis! :drunk: