PHP: Post ASPX form that uses 'WebForm_DoPostBackWithOptions' with cUrl
- by Oliver Cooper
I am trying to post an ASPX form which uses SharePoint with PHP.
Posting data works with standard forms, I just can't seem to get this form working. I did notice an onclick attribute on the submit button:
onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$PlaceHolderMain$btnSaveTask", "", true, "", "", false, false))"
I have never used ASPX and have no idea what this is.
It is not an authentication problem or something wrong with the url as it returns the webpage (which contains the form) fine.
Here is my PHP code:
function add($username, $password){
$data = array(
'ctl00$PlaceHolderSearchArea$ctl01$ctl00' => 'https://keystone.stpeters.sa.edu.au',
'ctl00$PlaceHolderSearchArea$ctl01$ctl04' => '0',
'ctl00$PlaceHolderMain$DateStart$DateStartDate' => '9/05/2012',
'ctl00$PlaceHolderMain$DateDue$DateDueDate' => '10/05/2012',
'ctl00$PlaceHolderMain$Title' => 'test again',
'ctl00$PlaceHolderMain$btnSaveTask' => 'OK',
'__spText1' => '',
'__spText2' => ''
);
$curl_handle = curl_init();
$fullurl = "https://keystone.stpeters.sa.edu.au/_layouts/StPeters.Keystone/MyTasks/MyTaskDetail.aspx?id=0&IsDlg=1"; //
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_URL, $fullurl);
$returned = curl_exec($ch);
curl_close ($ch);
return $returned;
}