1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Rep Power

    Using curl to submit a form in an iframe on another page?

    I've got some sample codes of curl, but i think it won't work with what i'm trying to do. Before i waste hours of time I want to make sure it can be done, that's why im asking it here.

    I am using an iframe with my affiliate ID in it for a site that searches available flights. The iframe shows a search box form. Hit submit and the flights show upin the same iframe.

    Now, for my site, I want the search form on one page and the search results on another page. This can't be done because everything is in an iframe out of my control.

    I thought of this way to do it:
    - Copy the iframe's form html and put that on 'mypage A'.
    - When someone fills the form and hits submit, it goes to 'mypage B' where there's the original iframe.
    - When the user has hit 'submit' on mypage A, the values he filled in must be copied to the original form in the iframe in mypage B and submit it.

    I never used curl but I thought, when mypage A form is submitted it goes to the curl page.
    Here the values get echoed in the post string.
    Then the curl page posts the data to the iframe page in mypage B.

    Here my problems start. Since i want mypage B show the search results which are in an iframe, to what url do I let curl post to?
    Also, the search form holds my affiliate ID, but the results page has no ID. So when i do find a way to show the search results in mypage B with this, curl posts the data directly to the result page, which doesn't hold my affiliate ID. I guess it's getting a cookie from the search form. But when the iframe search form gets skipped and curl directly posts to the results page, my affiliate ID is also skipped and possibly a cookie containing it too.

    I thought I had the solution until i ran into these problems.
    I wonder if there's a way to get the result I want but I'm starting to doubt it, so I hope the people here can tell me if this is even possible.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power
    cURL can't "post into an iframe", it runs on the server-side and has no concept of frames.

    cURL can submit a request to whatever URL the original form's action attribute points at. This will return the HTML of the results page, which you could write out into your own page. If you want to display these results in an iframe, the src of the iframe has to point at your local script that contains the cURL code. You'll have to transfer the values the user entered into the iframe page using a session.

    cURL will not copy cookies between the end-user and the remote site; that is not possible.

    Now, for my site, I want the search form on one page and the search results on another page. This can't be done because everything is in an iframe out of my control.
    If you're able to copy and paste the HTML for the original form then you don't need cURL to do this. Just create three pages and put the form HTML on the first and third pages. Modify the first page to submit its form to the second page rather than the remote site. Put an iframe on the second page that points at the third page. Write JavaScript on the second page that injects the submitted values into the form that is sitting on the third page inside the iframe, then use JavaScript to submit the form. You'll lose the ability to modify/control the iframe at that point, but it sounds like that doesn't matter.

    If you can't copy and paste the HTML for the original form, you'll need to use cURL on the third page to fetch a copy of the remote form.

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo