[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Forcing a post or get within a URL

Posted on 2007-08-06
11
Medium Priority
?
182 Views
Last Modified: 2013-11-05
If I have a form within a webpage that contains a field, can I force my data to display the desired search results just by passing the field variable with the url? The function that displays the result is called "showList".

For example:

http://www.mydomain.com/index.php?query=showList&field=NY

This brings up the page with the field prefilled in the box but does not currently initiate the search- I must click on the search button which then posts the form.
0
Comment
Question by:CaptWill
  • 4
  • 4
  • 3
11 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 19637946
You pass the variable to a script that do the search and display the result

$field = $_GET['field'];

$result = mysql_query("SELECT * FROM tablename WHERE field = '$field'");

and then display the result from the query.
0
 

Author Comment

by:CaptWill
ID: 19637979
Gamebits:
Can I do this directly from within the URL?

If so, how so I modify the syntax of the URL:

http://www.mydomain.com/index.php?query=showList&field=NY
0
 
LVL 4

Expert Comment

by:jentulman
ID: 19638007
What exactly are you trying to acheive here?

Are you trying to get the form to automatically submit, or are you trying to change the way the form submits the data?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:gamebits
ID: 19638011
Yes you can pass the variables from the link, if you'd like to use index.php to do the query (and probably display a default page if no query has been made yet) you will need something like a switch statement on the index page to let php know what to do.

0
 

Author Comment

by:CaptWill
ID: 19638016
I am trying to get the form to automatically submit with a search variable from the URL.
0
 
LVL 28

Expert Comment

by:gamebits
ID: 19638028
You don't have to go to a form and submit, go directly to the script from the URL.
0
 

Author Comment

by:CaptWill
ID: 19638119
Gamebits:

There is no script. There is a function called "showList".
0
 
LVL 28

Expert Comment

by:gamebits
ID: 19638128
Can you post the function?
0
 
LVL 4

Accepted Solution

by:
jentulman earned 1000 total points
ID: 19638150
Why have the step to show and submit the form at all, why not change the url that points to the form just point directly to the page that would process the form?

If you do want to keep this step then you could add an onload event to call a sybmit script one the page has loaded

<body onload="submitForm()">

and pop this in the head section

<script type="text/javascript">
function submitForm(){
      if(document.getElementById('elementid').value != ""){
            document.getElementById('formid').submit();
      }
}
</script>

This checks to see if a given element of the form isn;t blank and if so it submits the form.
Of course if you are filling the form in automatically with your server side script you copuld just add the submit form to the onload if needed and do away with the check.
0
 

Author Comment

by:CaptWill
ID: 19638151
Yes- the default is to show all records but I would like to only show records containing "NY" within the search field.
0
 
LVL 4

Expert Comment

by:jentulman
ID: 19638209
CaptWill, it's still a bit muddy as to what you are trying to acheive here. Could you post a walkthrough of what is meant to be hapening starting a couple of steps before the bit you're having a problem with?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question