473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is it Possible to Append Variables to a Query String?

17
I am trying to integrate a custom page into a shopping cart app written in PHP. The custom page is basically a part finder widget that helps customers find a car part based on the car's make, model, year, etc. This custom page has a form that submits the page to itself. It does this because I have four drop down menus, and the data in each following drop down is dependent on the previous selection. Since there was so much data, I didn't want to preload the page using Javascript. Instead, I did everything in PHP and just had the form submit to itself every time a drop down selection is made like this:

[HTML]<select name="carmake" onchange="this.form.submit()">[/HTML]

When I run this widget independently, it works. However, when I try to integrate it into the shopping cart, I run into problems because custom pages must be accessed through a "target" variable in the query string of the URL like this:

http://www.mysite.com/index.php?target=custompage
When I submit the form, instead of going to this page:

http://www.mysite.com/index.php?targ...age&make=honda
It goes to this page:

http://www.mysite.com/index.php?make=honda
In other words, the page is reloading to the index page, instead of to my custom page. So my question is this: Is it possible to reload to a URL that has a query string appended to it, and then add new variables to the query string when the page submits to itself?

The interesting thing is that when I type the whole URL directly into the address bar, the page works. I just can't accomplish this same behavior through the select lists.

I've been looking all over, and I haven't found anything helpful. Any help would be greatly appreciated.
Aug 18 '07 #1
6 3712
nbomike
17
I am trying to integrate a custom page into a shopping cart app written in PHP. The custom page is basically a part finder widget that helps customers find a car part based on the car's make, model, year, etc. This custom page has a form that submits the page to itself. It does this because I have four drop down menus, and the data in each following drop down is dependent on the previous selection. Since there was so much data, I didn't want to preload the page using Javascript. Instead, I did everything in PHP and just had the form submit to itself every time a drop down selection is made like this:

[HTML]<select name="carmake" onchange="this.form.submit()">[/HTML]

The "action" attribute of the form is set to submit to the current page.

When I run this widget independently, it works. However, when I try to integrate it into the shopping cart, I run into problems because custom pages must be accessed through a "target" variable in the query string of the URL like this:

http://www.mysite.com/index.php?target=custompage
When I submit the form, instead of going to this page:

http://www.mysite.com/index.php?targ...age&make=honda
It goes to this page:

http://www.mysite.com/index.php?make=honda
In other words, the page is reloading to the index page, instead of to my custom page. So my question is this: Is it possible to reload to a URL that has a query string appended to it, and then add new variables to the query string when the page submits to itself? If it's possible, can somebody show me how to do this? I'm thinking that maybe my action attribute needs to be set to something different.

The interesting thing is that when I type the whole URL directly into the address bar, the page works. I just can't accomplish this same behavior through the select lists.

I've been looking all over, and I haven't found anything helpful. Any help would be greatly appreciated.
Aug 18 '07 #2
Atli
5,058 Expert 4TB
Hi.

You could add a hidden <input> element in your form, which contains the variable you need to pass.
Like so:
Expand|Select|Wrap|Line Numbers
  1. $targetValue = $_GET['target'];
  2. echo "<input type=\"hidden\" name=\"target\" value=\"$targetValue\" />";
  3.  
Now, given that the form uses the GET method, the 'target' variable will be added to the url, along with it's old value and any other <input> elements that belong to the form.
Aug 19 '07 #3
nbomike
17
Hi.

You could add a hidden <input> element in your form, which contains the variable you need to pass.
Like so:
Expand|Select|Wrap|Line Numbers
  1. $targetValue = $_GET['target'];
  2. echo "<input type=\"hidden\" name=\"target\" value=\"$targetValue\" />";
  3.  
Now, given that the form uses the GET method, the 'target' variable will be added to the url, along with it's old value and any other <input> elements that belong to the form.
Thanks for the response! I actually just found this out myself a little while ago. I changed the form method to POST, too. Thanks again.
Aug 19 '07 #4
Atli
5,058 Expert 4TB
Thanks for the response! I actually just found this out myself a little while ago. I changed the form method to POST, too. Thanks again.
I'm glad you found your answer.
Changing to POST is a very good idea!

Good luck and I hope I'll be seeing you around.
Aug 19 '07 #5
pbmods
5,821 Expert 4TB
Heya, Mike.

I'll go ahead and move your thread to the Forum where an Expert will be more likely to find it.
Aug 19 '07 #6
pbmods
5,821 Expert 4TB
Merged duplicate threads.
Aug 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
4
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
2
by: Danny | last post by:
I want to extract a subset of fields from one table into another the master table has many fields the subset has about half, but still many. Is there a way I can just append the master into the...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
8
by: WordVBAProgrammer | last post by:
I've been struggling with this for a few days now. It worked originally as plain VB-type strings, but for some reason ceased creating the FileNm. I changed the code to use StringBuilder, but...
5
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table...
5
by: robertmeyer1 | last post by:
Hey, I have 2 append queries. The first is based off of code given and works great. For the second, I followed the format of the 1st and adjusted it to meet my needs. Query 1 works great. It...
7
by: Tobiah | last post by:
I wanted to do: query = "query text" % tuple(rec.append(extra)) but the append() method returns none, so I did this: fields = rec fields.append(extra) query = "query text" % tuple(fields)
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.