SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,732
    Mentioned
    31 Post(s)
    Tagged
    0 Thread(s)
    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).:
    Code:
    <? if (isset($_GET['submit']) : ?>  
    ..your stuff  processing/output code here 
    <? else?>
    ..your fom code here
    <? endif ?>
    hope that helps

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,732
    Mentioned
    31 Post(s)
    Tagged
    0 Thread(s)
    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;

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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 (don't get confused with LiveScript at GitHub though)

    Here is the original script http://www.sitepoint.com/forums/show...script-Refresh

    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 http://www.sitepoint.com/forums/show...=1#post5169828

    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...
    PHP Code:
    // create page before form output

    require "formOutput.php";

    // create page after form output 
    Which will allow your client-side JavaScript call...
    HTML Code:
    <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
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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 PHP HTTP Extension. No Javascript required.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's not unusual for me here!
    Maybe I'm a bit dyslexic, never been diagnosed but I do wonder sometimes.

    It might give him/her some inspiration.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  9. #9
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •