Form submission problem

mic_y

Expert Member
Joined
Dec 23, 2004
Messages
1,646
Reaction score
10
Location
Slaapstad
its probably just me being dumb, but any case, here goes:

I am coding a project using MVC5. On the login form I have options for external login which look like this:

Capture.JPG

The CSHTML for the external login portion of the form is as follows:
Code:
<div class="login-options">
@using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = ViewBag.ReturnUrl }))
{
   @Html.AntiForgeryToken()
   <h4>Or login with</h4>
      <ul class="social-icons">
           <li>
               <a class="facebook" id="Facebook" name="provider" value="Facebook" href="#" 
                   onclick="$(this).closest('form').submit()"></a>
            </li>
            <li>
               <button type="submit" class="facebook"  name="provider" value="Facebook" title="Log in using your                        
                   Facebook account" />
             </li>
             <li>
                <a class="googleplus" id="GooglePlus" name="provider" value="Google" href="#" 
                    onclick="$(this).closest('form').submit()" ></a>
              </li>
              <li>
                 <button type="submit" class="googleplus" name="provider" value="Google" title="Log in using your 
                    Google account" />
              </li>
         </ul>
       }
</div>

The buttons work perfectly, but I prefer the styling of the <a> tags. When I submit using those, the provider is not passed to the ExternalLogin method in the controller.

When clicking the button I can clearly see Account/ExternalLogin?provider=Facebook hitting the controller.

I am stumped by how to make sure this the provider variable is set before calling the .submit method for the form.
 
Last edited:
add a JavaScript function that sets a hidden form variable before the form is submitted and call that in the onclick instead?

Code:
function loginViaThirdParty(provider) {
   //hidden input value = provider
   //submit form
}

<a onClick="loginViaThirdParty('googlePlus');">
 
add a JavaScript function that sets a hidden form variable before the form is submitted and call that in the onclick instead?

Code:
function loginViaThirdParty(provider) {
   //hidden input value = provider
   //submit form
}

<a onClick="loginViaThirdParty('googlePlus');">


Thanks :) That worked a charm...
 
Top
Sign up to the MyBroadband newsletter
X