Solved

Building a Search Query to External Site

Posted on 2012-04-12
12
211 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
This article discusses four methods for overlaying images in a container on a web page
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 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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now