Best way to show a Javascript error message when submitting a SurfaceController Form.
Hi Guys,
I have a simple contact form that sends an email to the website owner based on contact details entered into the form. If there is a problem sending the data to the website owner's email e.g. SMTP password is incorrect or the SMTP server is down, I would like to display the error message as a JavaScript dialog (the email send code is written in C# code behind).
in the ActionResult for the code that handles the form submission (I'm using the BeginUmbracoForm to handle the submission) but i think the above is a bit of a hack and messy. It also doesn't allow me to return the user back to the page in the event of a problem.
Alternatively I was thinking of placing the error message dynamically on the page itself, but I'm not sure of the best way to accomplish this either. I was thinking along the lines of modifying a property on the page to contain my error message - but it's my understanding that properties are read only...?
What I would ideally like is to:
execute JavaScript code
execute an action result such as return RedirectToCurrentUmbracoPage()
I'm sure that must be a preferred way of accomplishing this type of behavior so if anyone has any pointers / examples that would be very useful.
I found a much better way to do it. Essentially creating a new ActionResult handler and the TempData variable to pass information back to the page from the controller. I was then able to use the TempData variables to change the resulting page and thus hide / show message boxes within the html based on my temp data values.
Best way to show a Javascript error message when submitting a SurfaceController Form.
Hi Guys,
I have a simple contact form that sends an email to the website owner based on contact details entered into the form. If there is a problem sending the data to the website owner's email e.g. SMTP password is incorrect or the SMTP server is down, I would like to display the error message as a JavaScript dialog (the email send code is written in C# code behind).
I know I can use something like:
return Content("
");in the ActionResult for the code that handles the form submission (I'm using the BeginUmbracoForm to handle the submission) but i think the above is a bit of a hack and messy. It also doesn't allow me to return the user back to the page in the event of a problem.
Alternatively I was thinking of placing the error message dynamically on the page itself, but I'm not sure of the best way to accomplish this either. I was thinking along the lines of modifying a property on the page to contain my error message - but it's my understanding that properties are read only...?
What I would ideally like is to:
I'm sure that must be a preferred way of accomplishing this type of behavior so if anyone has any pointers / examples that would be very useful.
Many thanks,
Damien
Hi Guys,
I found a much better way to do it. Essentially creating a new ActionResult handler and the TempData variable to pass information back to the page from the controller. I was then able to use the TempData variables to change the resulting page and thus hide / show message boxes within the html based on my temp data values.
Cheers,
Damien
is working on a reply...