Forum Moderators: coopster
Will try to keep simple.
I have been asked by a friend to do a site for his Estate Agents.
They have a database system; at the moment there website is running through a portal on their servers.
They want their own website and I have constructed this and the property search form, I have contacted the company and they have sent me 'as they say' all the info I need and that I should be able to understand XML to configure it.
They are a very unhelpful bunch.
I have got pretty far, BUT can seem to understand where I send the search form to.
Many Thanks
geoffb
[edited by: eelixduppy at 5:13 am (utc) on July 24, 2008]
[edit reason] removed some revealing specifics [/edit]
1) an HTML page that has the <form> on it
2) a "search results" page (written in PHP) which receives those form values
3) a script that assembles those values into an HTTP POST request to the provider's REST service, probably using cURL
4) a method of parsing the response (XML) and displaying it on your page.
I'm moving this thread over to the PHP forum now, since your initial hurdle is going to be using a REST service with PHP and cURL.
I'll meet you there
step 1)
create an HTML form, where the "action" is this:
<form action="results.php">
[... all your <input> stuff goes here]
</form>
make sure it has a submit button
<input type="submit" /> upload form.php to your server. Look at it and verify that when you press the submit button, you are directed to results.php
<form action="results.php" method="post" >
step 2)
Open a new text file in notepad. Call it "results.php"
paste this code onto the page:
<?php
print_r($_POST);
?>
"print_r" means, take this object and print everything in it into the output response.
"$_POST" is an array, it's a collection of stuff that was passed to this page along with the HTTP request. The form
Now fill out and submit your form again. See how the stuff you typed into the form is displayed on the results page, in a sort of serialized format.
So, say you have an <input> in your form that is named "dd".
In your results.php, you'll be able to get that value like this:
$_POST['dd']
step 3
construct an HTTP POST request to the web service. The POST sent to the web service must have all those user-entered values in it.
To prepare, you should RTFM (Read The Fabulous Manual):
[ca.php.net...]
And... go to any decent search engine and type the phrase "Sending HTTP POST with php cURL" and you'll find a few good tutorials and code samples.
This will be the trickiest part
<?php
$uri = "http://www.example.com/webservice/PostStuffToMe";$data = array(
'bedrooms'=>'3',
'bath'=>'2',
'style'=>'semi-detached',
'pricemin'=>'450000'
);$ch = [url=http://ca.php.net/manual/en/function.curl-init.php]curl_init[/url]($uri);
$post = [url=http://ca.php.net/manual/en/function.http-build-query.php]http_build_query[/url]($data);
[url=http://ca.php.net/manual/en/function.curl-setopt.php]curl_setopt[/url]($ch, CURLOPT_POSTFIELDS, $post);
$output = [url=http://ca.php.net/manual/en/function.curl-exec.php]curl_exec[/url]($ch);
[url=http://ca.php.net/manual/en/function.curl-close.php]curl_close[/url]($ch);
?>
And see where I defined elements of the $data array? That's where you'll substitute data that you get out of the $_POST, which came from the previous page's <form>
1) jump in, get your head battered, learn how to use HTTP and PHP cURL and XML, come out the other side with a working website and a bunch of new skills
2) hire someone else to do it
3) give up
It's admirable that you're going for #1. If time+deadlines are an issue, #2 is always an option. But don't give up - when you have questions, ask.