Solved

Building a Search Query to External Site

Posted on 2012-04-12
12
215 Views
Last Modified: 2012-04-16
I'm building out a form on my Drupal PHP page with the action set to go to "All for Good".

1) Here is the URL string that works on the "All For Good" site, searching for "education"

http://www.allforgood.org/search#q=education&num=10&start=1&vol_loc=22151&distance=25&type=all&sort=score&timeperiodstart=start%20date&timeperiodend=end%20date&cache=1

2) Here is my code on the action parameter. Needless to say, it's not working. I sense I'm missing something obvious.


action="http://www.allforgood.org/search?q=value&num=10&start=1&vol_loc=value&distance=25&type=all&timeperiodstart=everything&timeperiodend=everything" target="_blank" name="Form1">
0
Comment
Question by:sandshakimi
  • 6
  • 6
12 Comments
 
LVL 11

Expert Comment

by:un1x86
ID: 37837651
Hi

Just from looking at it I can see few differencies

q=value is in your second example but first it is q=education
also it is not ?q=education but #q=education with a hash!
0
 

Author Comment

by:sandshakimi
ID: 37838010
I showed the first example because that's the one that works.

Using the hash didn't do anything.
0
 
LVL 11

Expert Comment

by:un1x86
ID: 37838165
it does here. show me your link with the hash
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:sandshakimi
ID: 37838361
I mean...

Replacing "question" with "hash" in my action URL didn't do anything.
0
 
LVL 11

Expert Comment

by:un1x86
ID: 37838431
show me the url
0
 

Author Comment

by:sandshakimi
ID: 37838528
www.allforgood.org/search?q=military&vol_loc=boston&I1.x=122&I1.y=15#num=10&start=1&distance=25&type=all&timeperiodstart=everything&timeperiodend=everything&cache=1

Even with putting "hash", it's being auto replaced by a "question" mark.

I was thinking use urlencode or something like that?
0
 
LVL 11

Expert Comment

by:un1x86
ID: 37838973
The problem is that when you submit your form it will automagically create the URL using a questionmark. You can only change that using Javascript or you go though a PHP script first before you redirect it to the website.

The URL should be

http://www.allforgood.org/search#q=military&num=10&start=1&vol_loc=boston&distance=25&type=all&timeperiodstart=everything&timeperiodend=everything&cache=0
0
 

Author Comment

by:sandshakimi
ID: 37839066
Well, since I'm on Drupal, what's the PHP snippet for that?

Or is it easier with JavaScript?
0
 
LVL 11

Expert Comment

by:un1x86
ID: 37839242
maybe like this :)

<?php
$url = "#";
$first = true;
foreach($_GET as $key => $value)
{
	if(!$first)
	{
		$url.= "&";
	} else
	{
		$first = false;
	}
	$url .= $key."=".$value;
}
header("Location:http://www.allforgood.org/search${url}");
?>

Open in new window

0
 

Author Comment

by:sandshakimi
ID: 37841887
I see you're creating some variables, what is the code doing? And where on the page should I plug it in?
0
 
LVL 11

Accepted Solution

by:
un1x86 earned 500 total points
ID: 37841916
basically you have a form with input fields right? Set the action to the php file i provided you. like

<form action="route.php" method="get>
<input type="text" name="q" value="">
<input type="text" name="num" value="">
</form>

Open in new window


When you submit this form it will create an url called

route.php?q=value&num=value ......

route.php will then get the values and change its format and automatically redirect you to allforgood
0
 

Author Closing Comment

by:sandshakimi
ID: 37851141
Thanks

--

If you're able, I hope you can investigate a new question:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27677369.html
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

789 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