Solved

Building a Search Query to External Site

Posted on 2012-04-12
12
213 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
 

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now