Hello,

I am trying to find out how CURL to a webpage which has multiple submit buttons on its form and POST data.

I need to be able to select have reached the websites 'process.php' page by having clicked the 'submit' button - there is code to check which button the user clicked and of course different results for each button selected.

On a one button page the following code works fine and the data gets POSTed no problem:

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, "http://blah.com/process.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "jobid=32997&description=Curl loves me");

curl_exec ($ch);

curl_close ($ch);

This code doesn't indicated which button the user clicked on though...
Thanks for any help.

    Check what variables are posted if each submit button is used, and create sections in your code to set up the same variables to be sent.

    It's a bit of reverse-engineering if it uses some funny javascript

      ysu wrote:

      Check what variables are posted if each submit button is used

      Okay, this is what i have already been doing, checking the websites variables via a View Page Source and copying them. I also believe that all the various submit buttons he has uses all the same variable/data, but they just use it in different ways.

      So i think your response is helpful, but i don't think it answers my question.

      I would PRESUME his php/script code would check which button was clicked via an if else statement and the $_POST variable.

      My CURL code doesn't indicate which button was pushed, so i wouldn't enter any of his if-else statements. OR MAYBE the first one is selected by default.

        Try to think in server side. PHP does not know of any buttons, it'll receive some variables only. So the HTML form has to send out different vars for the different clicks to be identifyable.

        If he has a javascript modifying the HTML form values - on onClick or onSubmit for examle, - then they will be modified before sending.

        This is what you need to figure out - assuming the whole page is one form, does anything changes on the form if one or the other button is clicked?

        Or if he assignes names&values to the submit buttons, then he can check them.

          Hi Ysu,

          Okay his form doesn't contain any JS as far as i can see - its seems to be straight forward HTML.

          The form starts with:

          <FORM ENCTYPE="multipart/form-data" METHOD=POST  ACTION="http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post" NAME="message" TARGET="_self">
          

          and the submit buttons i mentioned are as follows:

          <INPUT TYPE=SUBMIT NAME="Preview" VALUE="Preview your Job Offer">&nbsp;<INPUT TYPE=SUBMIT NAME="Post" VALUE="Post your Job Offer">
          

          I'm not sure if this helps, but as you can see, the first button is "Preview".

          This site is a professional ESL job bank and i don't want to experiment submitting stuff to them without making sure my code is right - its a good way to get banned!!

          Soooooo, if you know how to POST that i want to 'click' button "Post", thats all i need - I think....

            These buttons will submit one variable each when clicked, their name/value pairs.

            $Preview = "Preview your Job Offer"
            and
            $Post = "Post your Job Offer"

            You might want to use the same encoding as the form (the multipart/form-data).
            Altho it's used on file transfer usually, so it may not be necessary. This I'm not sure of. You can use the CURLOPT_ENCODING option of curl.

              Write a Reply...