Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Deighton 23 posts 53 karma points
    Apr 07, 2013 @ 18:20
    Simon Deighton
    0

    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

  • Charles Afford 1163 posts 1709 karma points
    Apr 07, 2013 @ 21:44
    Charles Afford
    0

    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 :)

     

  • Simon Deighton 23 posts 53 karma points
    Apr 07, 2013 @ 21:48
    Simon Deighton
    0

    Thanks for the reply I'll check that out see if any of it makes sense!

    And yes its Visual Studio :)

  • Charles Afford 1163 posts 1709 karma points
    Apr 07, 2013 @ 21:52
    Charles Afford
    0

    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 :)

  • Mike Chambers 636 posts 1253 karma points c-trib
    Apr 08, 2013 @ 10:27
  • Simon Deighton 23 posts 53 karma points
    Apr 08, 2013 @ 12:15
    Simon Deighton
    0

    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!

  • Charles Afford 1163 posts 1709 karma points
    Apr 08, 2013 @ 12:24
    Charles Afford
    0

    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 385 posts 916 karma points
    Apr 08, 2013 @ 12:33
    gary
    0

    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

     

     

  • Mike Chambers 636 posts 1253 karma points c-trib
    Apr 08, 2013 @ 12:36
    Mike Chambers
    0

    you prob also already know that Contour supports MVC now too? ;-)

  • Simon Deighton 23 posts 53 karma points
    Apr 08, 2013 @ 12:54
    Simon Deighton
    0

    @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

  • gary 385 posts 916 karma points
    Apr 08, 2013 @ 13:18
    gary
    0

    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

     

     

     

     

  • Charles Afford 1163 posts 1709 karma points
    Apr 08, 2013 @ 14:54
    Charles Afford
    0

    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.  

  • Charles Afford 1163 posts 1709 karma points
    Apr 08, 2013 @ 15:15
    Charles Afford
    0

    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 :)

  • Simon Deighton 23 posts 53 karma points
    Apr 09, 2013 @ 11:14
    Simon Deighton
    0

    I think im running out of time, might have to invest in the contour, any have a coupon code :D

Please Sign in or register to post replies

Write your reply to:

Draft