Monorail - Form submission using GET instead of POST
Posted
by
Septih
on Stack Overflow
See other posts from Stack Overflow
or by Septih
Published on 2010-12-22T09:29:06Z
Indexed on
2011/01/04
8:53 UTC
Read the original article
Hit count: 314
Hello,
I'm writing some additions to a Castle MonoRail based site involving an Add and an Edit form. The add form works fine and uses POST but the edit form uses GET. The only major difference I can see is that the edit method is called with the Id of the object being edited in the query string. When the submit button is pressed on the edit form, the only argument passed is this object Id again. Here is the code for the edit form:
<form action="edit.ashx" method="post">
<h3>Coupon Description</h3>
<textarea name="comments" width="200">$comments</textarea>
<br/><br/>
<h3>Coupon Actions</h3>
<br/>
<div>Give Stories</div>
<ul class="checklist" style="overflow:auto;height:144px;width:100%">
#foreach ($story in $stories.Values)
<li>
<label>
#set ($associated = "")
#foreach($storyId in $storyIds)
#if($story.Id == $storyId)
#set($associated = " checked='true'")
#end
#end
<input type="checkbox" name="chk_${story.Id}" id="chk_${story.Id}" value="true" class="checkbox" $associated/>
$story.Name
</label>
</li>
#end
</ul>
<br/><br/>
<div>Give Credit Amount</div>
<input type="text" name="credit" value="$credit" />
<br/><br/>
<h3>Coupon Uses</h3>
<input type="checkbox" name="multi" #if($multi) checked="true" #end /> Multi-Use Coupon?<br/><br/>
<b>OR</b>
<br/>
<br/>
Number of Uses per Coupon: <input type="text" name="uses" value="$uses" />
<br/>
<input type="submit" name="Save" />
</form>
The differences between this and the add form is the velocity stuff to do with association and the values of the inputs being from the PropertyBag.
The Method dealing with this on the controller starts like this:
public void Edit(int id)
{
Coupon coupon = Coupon.GetRepository(User.Site.Id).FindById(id).Value;
if(coupon == null) {
RedirectToReferrer();
return;
}
IFutureQueryOfList<Story> stories = Story.GetRepository(User.Site.Id).OnlyReturnEnabled().FindAll("Name", true);
if (Params["Save"] == null)
{
...
}
}
It reliably gets called but a breakpoint on the Params["Save"] lets me see that the HttpMethod is "GET" and the only arguments passed (In the Form and the Request) are the object Id and additional HTTP headers.
At the end of the day I'm not that familiar with MonoRail and this may be a stupid mistake on my behalf, but I would very much appreciate being made a fool out of if it fixes the problem! :)
Thanks
© Stack Overflow or respective owner