Text variable in url string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Text variable in url string

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Text variable in url string

Post by requinix »

Yeah, it's possible. Anything in the URL can be accessed with $_GET.

Remember to urlencode whatever message you use.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Text variable in url string

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Text variable in url string

Post 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>";
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Text variable in url string

Post 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:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Text variable in url string

Post 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.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Text variable in url string

Post by synical21 »

Thanks you tasairis! :drunk:
Post Reply