Form submit > php page > http request > do something with the data

ok try to follow me on this one
i have a form
when i press submit, it goes to a php page
i want that php page to make a http request
i want the html returned from that http request returned to me as a string, so i can do something with it and display data on the php page accordingly
sorry if that sounds confusing, i explained it as best i could

Essentially what you want is called AJAX ( which will require Javascript ) in addition to PHP and HTML.

Conversely ( I only say this because you mentioned pressing submit) … you could have the form target its OWN PAGE. A a script at the top of the page could check to see if the form has been submitted ( give the submit button a name and value, check for the presence of that variable with the script. eg. ( assuming you use GET method for the form).:

<? if (isset($_GET['submit']) : ?>  
..your stuff  processing/output code here 
<? else?>
..your fom code here
<? endif ?>

hope that helps

no, ill try to explain differently
i guess the form doesnt have anything to do with it
when the php page loads, i want it to make an http request, and return the html as a string, so that i can use the html in different ways when the php page finishes loading and displays for the user

Unless you use ajax ( which essentially uses .js to call another document for a http request) , you can output anything to a page after the header has been sent.

when the php page loads, i want it to make an http request, and return the html as a string, so that i can use the html in different ways when the php page finishes loading and displays for the user Essentially correspond to the same point in time… so that’s why its hard to understand what what your goal is.

If you want to SAVE the HTML for use in another page… you could session_start(), write the whole HTML into a string variable (lest say: $html) before the header is sent. then echo $html; ( this ouputs your page for the user) , then store the string for latter use with $_SESSION[‘html’]=$html;

AJAX isn’t needed as XML isn’t needed, and asyncronous javascript without XML is not AJAX. I call it LiveScript (Live JavaScript). I can call it what I want as I was the one who came up with it :slight_smile: (don’t get confused with LiveScript at GitHub though)

Here is the original script

There are 2 ways it could be used. Request a php file that only outputs the string using server coded JavaScript (BAD as doesn’t work without JavaScript)
The other way is to make the page work with just PHP first. Then, using the querystring to differentiate between a “Live” hit from a standard hit you can call the same php file and get it to either output as HTML or JavaScript.

Here’s the method broken down a bit so easier to understand

The way I’d do your particular script is set an include to output just the result from the form, and place it in the directory structure where it can be called both server-side and client-side. Call it server-side in the usual way…

// create page before form output

require "formOutput.php";

// create page after form output

Which will allow your client-side JavaScript call…

<input type="submit" onclick="changeScript('formOutput.php?live=1&formValue1='+input1.value+'&formValue2='+input2.value); return false" />

To output just the string you require without executing the rest of the page (or skipping the bits that output when live is false)

I hope you’ve got the gist of it. I’m not very good at writing about it. Good at using it though :slight_smile:

You are all misunderstanding what the OP is wanting. To make an HTTP request from PHP. There are two ways to do that. cURL, or [URL=“”]PHP HTTP Extension. No Javascript required.

That’s not unusual for me here! :slight_smile:
Maybe I’m a bit dyslexic, never been diagnosed but I do wonder sometimes.

It might give him/her some inspiration.

lol logic earth is correct that is what i need, curl
i seem to faintly remember trying to use curl but having trouble “installing” it or something, like the server had to have it installed

I think I’d use simplexml_load_file if I wanted to read a third party website that I didn’t have access to at the server. It looks more what I’m used to in asp and javascript.

I think cURL can do a lot more though. Isn’t it used to get images from one server to another? I’ll ask in another thread.

EDIT:: Actually, a lot of errors in reading a page as XML using that method! But I would go along the lines of reading the page as XML if you can.