We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using a querystring parameter or User Session Variable

Development and Programming

indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

I’ve done a lot with .NET developemnt but am now supporting our company EE2 site. I want to have an EE2 page set up that can receive a variable as a part of the URL or a user session variable (or any other way you might suggest).

In .NET I would have the root URL appended with “?myvariable=foo” and then in the web page I would parce the “foo” and assign it to a textbox. Can someone help this lost soul?

       
mahalie's avatar
mahalie
60 posts
about 15 years ago
mahalie's avatar mahalie

Instead of querystrings I would use EE style URIs and use segments.

That is, instead of http://site.com/?myvar=foo

Make the uri http://site.com/foo and test for {segment_1 == 'foo'} in the template.

There are lots of ways to slice this donkey, including using querystrings (as you are used to) but you’ll probably have to mess with the .htaccess rules the remove index.php from the URIs (so you have clean URLs) to allow for it.

Learn more about the way EE urls work: http://ellislab.com/expressionengine/user-guide/general/urls.html

       
indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

Thanks so much and please forgive this novice at EE and PHP. So you are saying I could create a URI to go to the “donate” page of alarm-inc.org and pass a paramter “foo” as follows:

http://www.alarm-inc.org/donate/foo

And the “donate” page would use the paramater to fill a textbox as follows:

<input type=”text” name=”designation” value=”<?php echo $this=>EE->input->{segment_1}(‘designation’); ?>” >

and the “designation” textfield would initially display “foo”?

       
ll23's avatar
ll23
7 posts
about 15 years ago
ll23's avatar ll23

Actually it’s easier than that. Note, in your example, donate is segment 1, foo is sement 2 (unless you didn’t install EE in root of your site).

<input type=“text” name=“designation” value=”{segment_2}” />

http://www.alarm-inc.org/donate/foo would then output

<input type=“text” name=“designation” value=”foo” />

http://www.alarm-inc.org/donate/amilliondollars would then output

<input type=“text” name=“designation” value=”amilliondollars” />

       
indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

<input type=”text” value=”{segment_2}” name=”pg_billto_postal_name_first” />

yields ”{segment_2}” (including the quotes) in the name field.

EE is not installed in the root of the site the URI I used to get to the page is

http://alarm-inc.org/get_involved/donate/foo

       
indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

A little wild - http://alarm-inc.org/get_involved/donate/foo

<input type=“text” name=“pg_billto_postal_name_first” value=”{segment_3}” /> yields “foo” (with the quotes)

This is almost what I want except for the quotes

Can anyone help me strip the quotes from the beginning and end?

       
indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

Hot Zig!

http://alarm-inc.org/get_involved/donate/foo

<input type=“text” name=“pg_billto_postal_name_first” value={segment_3} /> yields “foo” (WITHOUT the quotes)

Thank you all so much!!!!

       
mahalie's avatar
mahalie
60 posts
about 15 years ago
mahalie's avatar mahalie

Ah so it sounds like you’re not using EE templates? Just the framework then? You have your work cut out for you!

Here’s some code I used recently for custom paging (using DB assets outside my EE install so couldn’t/didn’t want to use channels). Maybe helpful reference for you.

Re: stripping quotes, I remember reading about something against using preg_replace() in EE for performance reasons, not sure, you may have to google around for that.

My setup uses URIs like http://site.com/search_result/50/page5/ (50 is the page result set size, and page5 would be the 5th page of results.

//look at third URI segment for page size, default to 25 if not found
$page_size = $this->EE->uri->segment(3, 25);

//look at fourth URI segment for page number, default to 'page1' if not found
//use substring to remove 'page' from URI
$page_current = substr($this->EE->uri->segment(4, 'page1'),4);


$page_start = ($page_size * ($page_current - 1)) + 1;    //first row of the current page set
$page_end = ($page_start + $page_size) - 1;                //last row of the current page
       
indianabeck's avatar
indianabeck
5 posts
about 15 years ago
indianabeck's avatar indianabeck

Now using:

http://alarm-inc.org/get_involved/donate

<input type=“text” name=“pg_billto_postal_name_first” value={segment_3} />

yields a “/” (without the quotes)

I changed it to <input type=“text” name=“pg_billto_postal_name_first” value={segment_3}>

And it works in with and without the third segment “foo” http://alarm-inc.org/get_involved/donate and http://alarm-inc.org/get_involved/donate/foo

both work.

       
mahalie's avatar
mahalie
60 posts
about 15 years ago
mahalie's avatar mahalie

Glad things are working for you.

I just added the “/” compulsively because input is a self-closing tag (not a pair). http://www.w3schools.com/html5/tag_input.asp

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.