Just read the documentation. Eventhandlers are so nice.... :-) I did it like this:
public class FormRecordEventHandler : umbraco.BusinessLogic.ApplicationBase { public FormRecordEventHandler() { RecordService.RecordApproved += new System.EventHandler<RecordEventArgs>(RecordService_RecordApproved); }
void RecordService_RecordApproved(object sender, RecordEventArgs e) { var r = (Record) ((RecordService)sender).Record; if(e.Form.Name == "Comment Form") HttpContext.Current.Response.Redirect(string.Format("{0}#{1}", umbraco.library.NiceUrl(r.UmbracoPageId), r.Id)); } }
You can do it in the settings for the umbraco form in the form properties, use the content picker to specify the page you want the form to redirect to, no need to write any custom code.
@Tim: As I understand you can pnly "hardcode" which page to redirect to, not to the page itself, which is what I needed, because the form is on multiple pages.
@Soren, the page would reload on submit anyway, but if you were going to show something dependant on the submission (if say you were using it for blog comments), then you could either set the form to redirect to the page its on in contour (if the form is only on the one page), if the form is going to be on multiple pages, then the events option outlined earlier would probably be best.
@Rasmus, you're right, contour only lets you choose the one page, so in that case, events is the way to go.
How to redirect on submit?
How can I make Contour reload (redirect) the page that the form is on when submitting the form succesfully?
Just read the documentation. Eventhandlers are so nice.... :-)
I did it like this:
public class FormRecordEventHandler : umbraco.BusinessLogic.ApplicationBase
{
public FormRecordEventHandler()
{
RecordService.RecordApproved += new System.EventHandler<RecordEventArgs>(RecordService_RecordApproved);
}
void RecordService_RecordApproved(object sender, RecordEventArgs e)
{
var r = (Record) ((RecordService)sender).Record;
if(e.Form.Name == "Comment Form")
HttpContext.Current.Response.Redirect(string.Format("{0}#{1}", umbraco.library.NiceUrl(r.UmbracoPageId), r.Id));
}
}
Thanks for this!
Note: don't tie to the submit event to redirect because the form won't submit to Contour. Must use the approved event.
You can do it in the settings for the umbraco form in the form properties, use the content picker to specify the page you want the form to redirect to, no need to write any custom code.
Hi Tim.
What to do, if i want the current page to reload after a submit?
Do i have to use event there ?
@Tim: As I understand you can pnly "hardcode" which page to redirect to, not to the page itself, which is what I needed, because the form is on multiple pages.
@Soren, the page would reload on submit anyway, but if you were going to show something dependant on the submission (if say you were using it for blog comments), then you could either set the form to redirect to the page its on in contour (if the form is only on the one page), if the form is going to be on multiple pages, then the events option outlined earlier would probably be best.
@Rasmus, you're right, contour only lets you choose the one page, so in that case, events is the way to go.
:)
I ended up solving it by using an Event.
is working on a reply...