views:

69

answers:

1

I have a page in DNN like: http://nolimitswebdesign.com.dnnmax.com/test/tabid/57/ctl/Edit/mid/374/Default.aspx

I need to send a post request to that page using PHP+Curl which modifies the content of text area and saves it (like as if someone modified it manually and clicked the update button on that page). I doubt that with DNN it might not be possible. Please advise.

+1  A: 

Here is how I would approach the problem the same general technique will work on any website. In this context DNN is just an average ASP.Net website. First look at the javascript that runs when update is clicked:

__doPostBack('dnn$ctr374$EditHTML$cmdUpdate','')

Find the __doPostBack method:

function __doPostBack(eventTarget, eventArgument) {
  if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    theForm.__EVENTTARGET.value = eventTarget;
    theForm.__EVENTARGUMENT.value = eventArgument;
    theForm.submit();
  }
}

This is the standard doPostBack() method used in many ASP.Net forms. From this you can see that you want to fill in the __EVENTTARGET and __EVENTARGUEMENT hidden fields with the appropriate values from the method call and submit the form.

Of course you also need to fill in the data you actually want to save into the input control for the text box. It will probably be easier to do this if you use the basic text box mode of the HTML module, then you just need to set the value of a textarea rather than figure out where to insert the value in the fckEditor, and the technique will be still work if the site is configured to use the Telerik provider instead of the fck provider.

One thing to watch out for is that the control name may change from time to time, so you need to be sure you are reading the correct ids for the event target, and textarea not just hard coding something.

ScottS
Link at the end of comment contains the complete source code, i believe i have made all checks that you suggested, please check and provide feedback: http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/201/threadid/390240/scope/posts/Default.aspx
Shoaibi
@Shoaibi, a quick look at the code at the link looks generally right to me (caveat no PHP experience). I don't see anything to preserve the login cookie, that may be a problem. With the cookies sorted, I would use Live HTTP Headers to catch all the values from a manual post, and get the script to work with those values. Then I would edit the values that you want to change.
ScottS
I can edit the text inside textarea without being logged in, do i really need to maintain cookie?
Shoaibi
If i need to maintain cookies, how would i get that because the response return by GET curl is plain html and doesn't contain any cookie data
Shoaibi
There was a back to add the javascript postback code to the target url in a curl POST request, don't remember where i saw it...
Shoaibi
Even without a login DNN issues a cookie. It is probably (not certainly) required. See http://www.electrictoolbox.com/php-curl-cookies/ for some info on maintaining cookies with curl. When interacting with a website gets complicated I prefer automating a browser via selenium to scripting with curl/httpwebrequest etc.
ScottS
Hmmm, i can't go for selenium because this script has to run in cron and operate on hundreds of urls. Tried updating code by including cookie: http://pastebin.com/P62rTFhg but this doesn't work as well... One side question, how would i go about debugging it on DNN part if i want to?
Shoaibi
@Shoaibi you can get the DNN source and symbols from codeplex and then attach a debugger from visual studio. That can be complicated especially if you don't know what code is causing the problem. A better bet may be a proxy (e.g. fiddler) that allows you to watch everything that is exchanged between browser and server, and then work that into your script. You need to check out the get and post operations, if the script gets and posts in the same manner as the browser it should all work.
ScottS