__doPostBack()
is indeed an ASP.NET thing. Here's what the function does:
var theForm = document.forms['FORMNAME'];
if (!theForm) {
theForm = document.FORMNAME;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
Basically, it sets the values of two hidden fields (__EVENTTARGET
and __EVENTARGUMENT
) to the respective values of the parameters. Then it submits the form.
If you wanted to, you could continue using the PHP HTML parser to do the job, but when you encounter one of these __doPostBack()
links, you'd have to craft a POST request manually. At a high level, you'd be looking at something like this:
- Get the current form values. You'd probably have to loop through each
input
element, etc. and add the values to an array. If there are no text boxes, checkboxes, etc. on the page, you should only be left with the hidden fields .NET embeds by default (e.g., __VIEWSTATE
, __EVENTVALIDATION
, etc.).
- Parse out the values passed to
doPostBack()
and overwrite the existing values for __EVENTTARGET
and __EVENTARGUMENT
.
- Craft your POST request. I'm not sure what (if anything) the library you're looking at provides this way, but a popular way to do this from PHP would be through the cURL extension. For an example, see http://davidwalsh.name/execute-http-post-php-curl.
- Get the HTML result and parse with the library as usual.
Alternatively, if you're always making pretty much the same request to the same page, you could probably skip some steps in parsing the form and just jump straight to crafting the POST request.
That's not going to be a ton of fun, but it would work for this case. If you needed to deal with more complicated cases involving JS, or if you just want to handle this a different way, there are (as you mentioned) libraries that basically drive browsers and handle these things for you. The two that come to mind first are:
There are other options too, but I don't know of any that are going to be quick and easy to integrate into an existing PHP script.