Solved

Building a Search Query to External Site

Posted on 2012-04-12
12
214 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

776 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