Does anyone know of any great tutorials that guide through how to create a very basic form (name email message) for an mvc3 umbraco site? Im a front end dev at heart and this form stuff is a bit over my head :(
I know there is Contour, but for this project its a bit on the expensive side for me.
Hope this sort of makes sense. Please let me know and i will try and help some more. :). My next post in my blog is going to be about surface controllers :).
No problem let me know how you get on and read the documentation @ the url i provoided. There is lots there about razor and mvc with Umbraco :). Sorry about the spacing on my last post. Charlie :)
Hi Mike thanks for the link but im already quite familiar with that page, Ive built a fair few websites with umbraco MVC already, its just the form funtionality that i've never had to do before!
Its should be easy enough for you. Really you are doing is POSTING data either by a standard HTTP POST or AJAX POST to a controller and action. Dealing with the data, setting up the email, sending the email, returning a result, displaying the result to the user. Either via a modelstate error or a re-rendered partial view on success :)
@Gary - I'll look at the diplo form later this evening thanks, ive had a quick look but it doesnt really seem to explain how I then email the completed form to a person.
@Mike - Yes I mentioned that in my original post, however currenlty its a little expensive for me, and I'd like to try and gain at least a little understanding, and something I can re-use in the future!
Gary, yes that is a way of doing it, You should be able to use my apporach and then have a method in your class that sends the email based on what gary has provided IE.
Razor Form Tutorials?
Does anyone know of any great tutorials that guide through how to create a very basic form (name email message) for an mvc3 umbraco site? Im a front end dev at heart and this form stuff is a bit over my head :(
I know there is Contour, but for this project its a bit on the expensive side for me.
Thanks for your time
Hello. Firstly i would get some code running in MVC. You can find some information here :).
http://our.umbraco.org/documentation/Reference/Mvc/
I assume you will have visual studio?
What you need to do to begin with is create a class liabary with a blank class that builds into the www project bin.
// your liabary
Your class will look something like this:
namespace
{
YourControllerNameSurface: SurfaceController // this must inherit from surface controller
{
public ActionResult YourName (yourformmodel yfm) // this will be some sort of form model to hold your fom data
{
Enum of result = your method (); // do something with this form data in a method and return a result
//handel the result
return partialView(yourview, yourmodel)
}
}
//model
public string firstname{get;set;}
public string lastname{get;set;}
ect.......
//create a method and do something with the properties.
//build these classes into your wwwroot bin directory
//in visual open your www root project as a website
//In your wwwroot project create a partial view
//this will call the form partial view and pass your form model into it
@Html.partialView("yourpartialviewname", new yourformmodel());
so in yourpartialviewname you can call your controller by
@html.form("YourControllerNameSurface","YourName");
{
}
Hope this sort of makes sense. Please let me know and i will try and help some more. :). My next post in my blog is going to be about surface controllers :).
Charlie :)
Thanks for the reply I'll check that out see if any of it makes sense!
And yes its Visual Studio :)
No problem let me know how you get on and read the documentation @ the url i provoided. There is lots there about razor and mvc with Umbraco :). Sorry about the spacing on my last post. Charlie :)
http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
another starting point resource.
Hi Mike thanks for the link but im already quite familiar with that page, Ive built a fair few websites with umbraco MVC already, its just the form funtionality that i've never had to do before!
Its should be easy enough for you. Really you are doing is POSTING data either by a standard HTTP POST or AJAX POST to a controller and action. Dealing with the data, setting up the email, sending the email, returning a result, displaying the result to the user. Either via a modelstate error or a re-rendered partial view on success :)
Hi Simon
Dan Diplo has a contact form that should work for you - it is an outline, but easily adaptable.
http://our.umbraco.org/projects/website-utilities/diplo-razor-form
Has validation and everything you need.
Regards
G
you prob also already know that Contour supports MVC now too? ;-)
@Charles - If only it was that simple
@Gary - I'll look at the diplo form later this evening thanks, ive had a quick look but it doesnt really seem to explain how I then email the completed form to a person.
@Mike - Yes I mentioned that in my original post, however currenlty its a little expensive for me, and I'd like to try and gain at least a little understanding, and something I can re-use in the future!
I hate forms already. :D
Hi Simon
This is a real "cheap" way of doing it, but it works;
@helper SendEmail(ContactFormModel formModel)
{
var trial = @Umbraco.Join(" ", "You have received an email from:", "<br/>", "<br/>",
@formModel.FirstName,
@formModel.LastName, "<br/>",
"Telephone Number: ", @formModel.Telephone, "<br/>",
"E-mail Address: ", @formModel.Email, "<br/>",
"Comments: ", @formModel.Comment, "<br/>", "<br/>",
"With regards,", "<br/>", "<br/>", "www.your website.com");
MailMessage mail = new MailMessage("Your From Address", @formModel.Email, "Your Title");
mail.IsBodyHtml = true;
mail.Body = trial;
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
}
You will find the original at the base of the form.
Thanks to Dan, I used this to get my understanding as I was in the same position as yourself.
Any credit goes to Dan Diplo.
(ok, apart from the the join part, sure Dan would have a far cleaner way of achieving it)
If you get stuck this evening Simon, should be about to give you a hand.
All the best
G
Gary, yes that is a way of doing it, You should be able to use my apporach and then have a method in your class that sends the email based on what gary has provided IE.
MailMessage msg = new MailMessage();
msg.to.add("your recipient");
msg.body("your body")
ect ect.
I am going to do this as my next blog post, so if you need a walk though i will cover it there. charlesafford.com. Will be up in about a week :)
I think im running out of time, might have to invest in the contour, any have a coupon code :D
is working on a reply...