Copied to clipboard

Flag this post as spam?

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


  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 12:20
    Scott Hugh Alexandar Petersen
    0

    Two forms on the same page

    I almost seems to be a classic right - but it ain't I think.

    I have the following code in my master template

        <div id="SiteSearch">
         <input type="text" name="search" class="SearchTextBox" />     
         <asp:ImageButton ID="btnSearch" ImageUrl="~/media/images/SearchButton.png" CssClass="SearchButton" BorderWidth="0" PostBackUrl="~/soeg.aspx" runat="server" CausesValidation="false"></asp:ImageButton>
        </div>
    <umbraco:Macro doc2form thing here />

    The doc2form works on frontpage only and not on subpages.

    If I remove the search box entirely it will work on subpages as well.. How do I fix this?

    Thanks.

    Oh almost forgot:

    UV: 4.0.2.1
    ANV: 2.0
    WAIV: 2003/IIS6
    S: nothing
    ADDOWYDBTIH: above :)

  • dandrayne 1138 posts 2262 karma points
    Nov 17, 2009 @ 12:34
    dandrayne
    0

    Hi Again :-)

    A solution would be to only wrap the <form runat="server"> </form> around the area that you need it, instead of around the whole masterpage.

    I usually just wrap the bodyText page field in the templates with the form tag if authors are to insert forms themselves, otherwise I just wrap the form around the actual doc2form macro code in the template

    Dan

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 12:42
    Scott Hugh Alexandar Petersen
    0

    Hiya back :)

    I am not sure if I did it correctly. Because there will be at least two forms on the same page. Will this then mean that I should add two <form runat="server"></form> tags?

    Scott

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 13:12
    Scott Hugh Alexandar Petersen
    0

    Okay, well I solved it by using javascript which I think is totally crazy - however I did this:

        <script type="text/javascript">
         function OnKeyPress(event)
         {
          if(event.keyCode == 13)
          {
           document.getElementById('btnSearch').click();
           return false;
          }
         }
        </script>
        <div id="SiteSearch">
         <input type="text" id="txtSearch" name="search" class="SearchTextBox" onkeypress="return OnKeyPress(event);" />
         <img src="/media/images/SearchButton.png" class="SearchButton" id="btnSearch" alt="søg" onclick="location.href='/soeg.aspx?search='+ document.getElementById('txtSearch').value" />
        </div>

    So that the search box is using javascript.

    When clicking enter on that box it will click the "image" so to say and that's it.

    When hitting enter in any other form it will just submit that specific form.

    Scott

  • dandrayne 1138 posts 2262 karma points
    Nov 17, 2009 @ 13:44
    dandrayne
    2

    That's a solution, but usually not necessary.

    Here's a stripped-down version of a master template that we use on a site of ours.  You canh ave two forms on a page, they just can't be nested

    <%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="head" >

    </head>
    <body>
    <div class="page_container">
    <div class="page_header">

    <form action="http://whateveryoulike" method="post">
    <p>
    <label for="user_name">User Name</label>
    <input name="user_name" type="text" id="user_name" />
    </p>
    <p>
    <label for="password">Password</label>
    <input name="password" type="password" id="password" />
    <input type="submit" value="Sign in" class="button" />
    </p>
    </form>
    </div>
    </div>

    </div>
    <form id="MasterForm" runat="server">
    <asp:ContentPlaceHolder ID="MasterContentPlaceHolder" runat="server"></asp:ContentPlaceHolder>
    </form>
    </div><!--end of page_container-->
    </body>
    </html>
    </asp:content>

    Dan

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 14:35
    Scott Hugh Alexandar Petersen
    0

    Ah now I see what you do - one of them is a standard html form (both are not asp.net forms)

    Which is why it allows you to have two form tags.

    This solution will not work as both were asp.net controls however after I changed the search box to regular html form controls (then it could work of cause) it works with both forms in the same form tag.

    Dan, thanks for the input.

    Scott

  • Chris Koiak 700 posts 2626 karma points
    Nov 17, 2009 @ 14:54
    Chris Koiak
    0

    Scott - I think you've found the ideal solution.

    However if you want to read more, an eariler discussion is available at http://our.umbraco.org/forum/templating/templates-and-document-types/4101-Multiple-forms-in-templates-?sort=karma

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 16:05
    Scott Hugh Alexandar Petersen
    0

    Thanks Chris, it was rather helpful and actually found that it was excactly the same thing Dan wrote (thanks to both, and I think I will opt for that solution because it will spare me the js).

    Scott

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Nov 17, 2009 @ 16:09
    Scott Hugh Alexandar Petersen
    0

    And just to confirm, it works like a charm and it is much better that way. Thank you for the eyeopener both of you.

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Dec 02, 2009 @ 15:56
    Jan Skovgaard
    0

    Hmm...I have removed the server form and attached the form-tag around the two forms I have on my site...

    But it does not really work very smooth...

    On my page I have a subscription form and an unsubscription form - This only happens when a visitor goes to the "unsubscription" page since the subscription form is a global element on the site.

    If one for some reason enters the website through the unsubscription and actually want's to subscribe for the newsletter then the e-mail entered appears on the unsubscription form field once I hit submit.

    How can I solve this? I guess I'm missing something obvious but I just can't seem to get my mind right...

    /Jan

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Dec 11, 2009 @ 16:46
    Scott Hugh Alexandar Petersen
    0

    you should not have a form tag around the other two forms...

    <form method="post">
    html form
    </form>


    <form runat="server">
    asp.net form
    </form>

    What kind of forms do you have on your page?

    One search and one (un)subscription?

  • 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