Solved

Building a Search Query to External Site

Posted on 2012-04-12
12
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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…
A big percent of today’s marketing activity is performed through the online environment. The marketing strategies that have existed a decade ago no longer relate to what’s happening today. We’re currently facing a revolutionary era, called the digit…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

734 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