tags:

views:

78

answers:

2

Is there a way to automatically go to a URL returned via XML from an API call? For instance I call and it returns the XML file that I parse with simple_xml_load() and then I create a link like so,

<a target=_blank href='" . $title->links->homedetails . "?scrnnm=Nexus-Software'>".
$title->address->street . "</a>

But I do not want the user to have to click, is there a way to have the page automatically go to that returned link after submitting the form?

+1  A: 

If I understood your question correctly this would do the trick:

<?php header('Location: '.$title->links->homedetails.'?scrnnm=Nexus-Software'); ?>

It redirects the user to the location specified. You just have to watch out to call it before any output is sent to the browser.

You can find some more info at: http://pl2.php.net/manual/pl/function.header.php

jondro
I was looking at headers yeah, but lots will be on this page first because it is a form. Do you mean have the form post to another page that just has that header on it? If so can I get post variables to use in the header?
thatryan
Is the API call based on what the user put in the form? If, yes than you can use a different script to process the form, use output buffering, or just put the form processing code before the HTML. That way the header will execute before stuff is sent to the browser.
jondro
Yes the API call uses a few fields from the user input data form. So if I call another page with the form submit and process the form first, then just put the header under the form processing?
thatryan
You can't send the user to the new URL via POST; the Location header sends a HTTP 302 code, which makes the browser perform a GET on the new URL. But you may be able to pass data from your form with GET parameters, if the new URL will take them.
Nathan
A: 

You could also try displaying a confirmation page to the user and using or a JavaScript onLoad event to send the user immediately to the new URL.

Nathan