Forum Moderators: coopster

Message Too Old, No Replies

xml help for novice

         

geoffb

10:51 pm on Jul 21, 2008 (gmt 0)

10+ Year Member



Hi All,

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]

httpwebwitch

12:36 pm on Jul 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might have a REST Web Service on your hands. They're cute and cuddly but require some special equipment to handle them safely.

without mentioning the name of the company, can you clarify - did they give you a URL where you can make a request for search results, and get XML in the response?

httpwebwitch

2:38 pm on Jul 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi geoffb,
Here's what you will need going forward:

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

geoffb

8:39 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



Hi hww,

This is where I am stuck, part 2 3 and 4 are unknown territory for me.

Im even unsure as to what I should call the results page...ect

geoffb

httpwebwitch

8:54 pm on Jul 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



perhaps this could become a "how to" thread. Let's start from the very beginning

step 1)
create an HTML form, where the "action" is this:

<form action="results.php">
[... all your <input> stuff goes here]
</form>

save it as "form.php"

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

httpwebwitch

8:59 pm on Jul 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, I almost forgot:
step 1b)
make sure your form uses the POST method.

<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.

geoffb

9:33 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



hi hww,

Done all that got the code typed in back, Like this:

Array ( [pf] => 125000 [pt] => 250000 [be] => 0 [pc] => [ty] => HOUSE [display] => Yes [perpage] => 5 [od] => AP [upw] => undisclosedcodeundisclosedcode )

whats next for me?

geoff

httpwebwitch

5:04 am on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



having ensured that the form is working properly, you can now access user-entered values by reference to the $_POST array.

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

eelixduppy

5:16 am on Jul 24, 2008 (gmt 0)



As for step 4 given by httpwebwitch, SimpleXML [php.net] will make this step go MUCH more smoothly so if you have PHP 5 I'd recommned using that to parse the response. Again, read the manual at the link above and it should give you enough examples to start writing your own code.

httpwebwitch

5:20 am on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is one such code sample:

<?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);

?>



In order for this to make sense, read about each of the functions used via links to the PHP manual.

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>

geoffb

10:33 am on Jul 24, 2008 (gmt 0)

10+ Year Member



now my head is totally battered!

geoffb

httpwebwitch

1:29 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL geoffb. From the start you know you had three options:

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.