Copied to clipboard

Flag this post as spam?

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


  • javafun 17 posts 50 karma points c-trib
    Feb 11, 2019 @ 09:37
    javafun
    1

    Is it possible to handle more than one submit button?

    Hi All

    I am running into this issue recently. The current form has one submit button does post to the surface controller to persist the form data.

    My client has a new requirement and would like to add another button on the same form to allow their users to save the data as draft.

    I went through the forum and google, found the following similar question, unfortunately, there wasn't clear solution to fix this issue.

    https://our.umbraco.com/forum/templates-partial-views-and-macros/90611-how-to-i-implement-two-submit-buttons-in-the-same-partial-view-hitting-the-same-surface-controller

    Can someone point me a direction how to handle multiple submit buttons with Umbraco surface controller?

    Appreciate for your help.

  • Emiel 31 posts 124 karma points
    Feb 11, 2019 @ 09:53
    Emiel
    0

    What I've used is the "formaction" attribute. Example:

    <form class="form" action="/url" method="get">
        <div class="inputs">
            <input class="input" placeholder="Name">
        </div>
        <div class="form-buttons">
            <input class="submitbutton" type="submit" value="Submit form">
            <input class="link" formaction="/different-action" value="Submit to different action" type="submit">
        </div>
    </form>
    

    You can read more about it here: w3schools link

  • javafun 17 posts 50 karma points c-trib
    Feb 11, 2019 @ 10:36
    javafun
    0

    Hi Emiel

    Thanks for your quick response.

    In your code snippet, you specify method="get" in the form tag, is this the trick to handle multiple form post?

    My form used formaction and generate via @Url.SurfaceAction, however the only difference to your example is the form method, it turns out no matter which button I clicked, it always post to the form's action, not the formaction I specified in the button.

    Appreciate for your help.

  • Emiel 31 posts 124 karma points
    Feb 11, 2019 @ 12:02
    Emiel
    0

    Whether it is "POST" or "GET" shouldn't be the issue, the page it was submitting to was a Vue app which had additional parameters needed, hence the usage of "GET".

    Honestly, I'm not really a big fan of using either @Url.SurfaceAction or @Html.BeginUmbracoForm, could you try to make the form in html, and then try to add the route you're trying to hit to those buttons?

  • javafun 17 posts 50 karma points c-trib
    Feb 11, 2019 @ 13:11
    javafun
    0

    Hi Emiel

    Again, thanks for your response.

    However, I think you suggested approach only works if I register MVC standard route, meanwhile I lose all Umbraco context e.g. I'm no longer able to use return CurrentUmbracoPage if validation failed. I have to complete change the way how I handle the entire form which is not very ideal for my current situation.

  • Craig Mayers 164 posts 508 karma points
    Feb 11, 2019 @ 15:21
    Craig Mayers
    0

    Hi javafun,

    If you can't get it working using the suggestions Marc posted on the the previous post you mentioned...

    Then I would say the easiest solution for this would just to create a second partial view which POST's directly to your new Action method on your current SurfaceController.

    Thanks

    Craig

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies