I have some Javascript that checks for a users cookie when they land on our page, and if they haven't been on the page before, a form appears to log their name and other data as additional cookies. I would like to also post this form data to a file on the Umbraco server just don't know how, any suggestions?
When the form posts it will look for a surfacecontroller called ContactController and call it's submit action...
eg
public class ContactController : SurfaceController {
public ActionResult Submit(ContactModel model)
{
if (!ModelState.IsValid)
return CurrentUmbracoPage();
// do stuff with posted values...
return RedirectToCurrentUmbracoPage();
}
}
If I've got the wrong end of the stick, and you'd be posting the data asynchronously via javascript, then create an UmbracoApiController to receive the posted data:
public class TrackUserController : UmbracoApiController
[System.Web.Http.HttpPost]
public HttpResponseMessage TrackUser(ContactModel postedData){
// do something to persist tracked data
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
}
Thanks Dennis, but I really need more of a way to post to a data base or save to a file on the server. I think there would be too many form submissions to keep track of with just emails.
you could either use an UserControl (userControl.ascx + Codebehind, created in Visual Studio) and integrate it by a Macro into your umbraco-page or you just use an PartialView, that handles the post.
Post Form Data Without Contour
I have some Javascript that checks for a users cookie when they land on our page, and if they haven't been on the page before, a form appears to log their name and other data as additional cookies. I would like to also post this form data to a file on the Umbraco server just don't know how, any suggestions?
Thanks!
Hi Steve
An Umbraco Surface Controller is designed to handle the posting of a form:
https://our.umbraco.org/documentation/reference/routing/surface-controllers
So if you have a simple form to post name, email etc, you'd create a plain model class eg
Then put your form in a partial view like so:
When the form posts it will look for a surfacecontroller called ContactController and call it's submit action...
eg
If I've got the wrong end of the stick, and you'd be posting the data asynchronously via javascript, then create an UmbracoApiController to receive the posted data:
https://our.umbraco.org/documentation/reference/routing/webapi/
We are using webforms not MVC unfortunatly.
I've seen some Umbraco sites that wrap the form inputs in a div that calls a Javascript function, I am assuming something to post the form data.
Hi Steve.
Could this package maybe be an option for you depending on which Umbraco version that you are using.
https://our.umbraco.org/projects/website-utilities/cultiv-razor-contact-form/
Hope this can help you.
/Dennis
Thanks Dennis, but I really need more of a way to post to a data base or save to a file on the server. I think there would be too many form submissions to keep track of with just emails.
Hi, Steve,
you could either use an UserControl (userControl.ascx + Codebehind, created in Visual Studio) and integrate it by a Macro into your umbraco-page or you just use an PartialView, that handles the post.
Here is an example:
is working on a reply...