Copied to clipboard

Flag this post as spam?

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


  • Jules 276 posts 587 karma points
    Feb 28, 2014 @ 12:41
    Jules
    1

    Adding custom attribute to BeginUmbracoForm

    Hi

    Trying to integrate Zurb foundation validation into an umbraco MVC implementation and need to add a custom attribute to the MVC form while using BeginUmbracoForm.

    Anyone know of a way of doing this?

    Jules

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 28, 2014 @ 12:59
    Dirk De Grave
    2

    Here you go:

    @using (Html.BeginUmbracoForm("Action", "Surface", null, new Dictionary<string, object> { { "attribute", "attribute-value" } }))

     

    /Dirk

  • Jules 276 posts 587 karma points
    Feb 28, 2014 @ 15:50
    Jules
    0

    Marvellous.  Works perfectly

    Cheers

    Jules

  • Craig100 1136 posts 2523 karma points c-trib
    Sep 07, 2014 @ 15:29
    Craig100
    0

    Hi,

    After using the Umbraco.tv Surface Controllers/Handling Posts tutorial and Dirk's answer above, I still can't fathom out the syntax for adding the html attributes role="form" id="bookingForm" to this:-

    @using(Html.BeginUmbracoForm<myProject.Controllers.bookingFormSurfaceController>("HandleFormSubmit")){
    
    theform
    
    }
    

    so the final HTML output would be this:-

    <form action="/booking" role="form" id="bookingForm" enctype="multipart/form-data" method="post">
    

    Any clarity appreciated :)

  • Tim Anderson 20 posts 83 karma points
    Sep 09, 2014 @ 02:37
    Tim Anderson
    1

    Add to the top of your view the following line

    @using myProject.Controllers;
    

    Then change "Action" to "HandleFormSubmit" and "Surface" to "bookingFormSurface" in dirks example above to route the form to your controller.

    finally your dictionary object would be.

    new Dictionary<string, object> { { "id", "bookingForm" }, {"role", "form"} }))
    

    This should work, there are in fact many overloads to the BeginUmbracoForm method which can be found in the documentation here:

    Mvc Forms documentation

  • Craig100 1136 posts 2523 karma points c-trib
    Sep 09, 2014 @ 10:43
    Craig100
    0

    Thanks for that. It worked perfectly and helped me understand the syntax.

    The issue I have with the documentation is that without real-world examples I can't make head nor tail of them. Same with Microsoft's docs. They're ok as a reference (i.e. if you already know it but have just forgotten) but useless for learning. For instance they don't tell you what the HTML output will be, which is the whole point of doing it in the first place;)

  • Daniel Gillett 72 posts 149 karma points
    Feb 05, 2017 @ 12:25
    Daniel Gillett
    0

    hello!

    i'm finding this information very helpful. However I have a unique situation with the HTML that I have in my form that I am bringing into Umbraco/Partial View:

    There are two issues:

    1) <input type="email" required>

    Is this bad HTML?? Because I cannot render out just the "required" element for the input tag because I have to add a object which wants the key|value pair. The only way I can do it is to add the object:

    new { @input = "required" }
    ...but the render result is

    <input type="email" input="required">
    
  • Daniel Gillett 72 posts 149 karma points
    Feb 05, 2017 @ 12:31
    Daniel Gillett
    0

    The second issue I'm having with using the Html helper methods is to try and render this:

    <label class="i"><span class="start">*</span>Your Name</label>
    

    I'm currently using it this way, which alwmost works:

    @Html.LabelFor(m => m.Name, "* Your Name", new { @class = "i" })
    

    The result of this is close:

    <label class="i" for="Name">* Your Name</label>
    

    ...my problem is that I cannot use the span tag with the "start" class attribute.

    Any ideas? If this is not way to do this then fine; I just want to be sure there isn't some way of doing this to match the markup that I received.

    Thanks very much for any assistance. Daniel

  • Daniel Gillett 72 posts 149 karma points
    Feb 05, 2017 @ 12:54
    Daniel Gillett
    0

    Update! ...I'm still having problems with adding the span tags in the label to color the * however I have found a sort of workaround for the 1st issue - the required element of the input tag:

    @Html.TextBoxFor(m => m.Name, new { @required = "" })
    

    Which comes out looking like this:

    <input id="Name" name="Name" required="" type="text" value="" />
    

    ...and it works. The jquery is still able to pick up the field and is doing the client side validation.

    Hope this may be of help to anyone else who hit this problem.

  • Steve Goldsmith 1 post 71 karma points
    Mar 16, 2020 @ 12:10
    Steve Goldsmith
    0

    I'm trying to reload my form with an anchor in the url

    topic-address-finderare-you-taking-part-in-the-trial"

    Any ideas would be most welcome?

Please Sign in or register to post replies

Write your reply to:

Draft