0

I'm creating a way to login using different providers from angular. I'm having an issue submitting my form, the loginProvider value is not being sent to the server. I have a form which looks like so:

<form #form method="post" class="form-horizontal" [action]="loginUrl">
    <div>
        <p>
        <button ion-button block (click)="loginFrom(form, 'StripeConnect')" title="Log in using Stripe">
            Stripe Connect
        </button>
        <button ion-button block (click)="loginFrom(form, 'google')" title="Log in using Google">
            Google
        </button>
            <input type="hidden" name="provider" [value]="loginProvider">
            <input type="text" name="entryCode" placeholder="Entry Code">
        </p>
    </div>
</form>

In my typescript file I have the following:

loginProvider: string
loginFrom(form, loginProvider) {
  this.loginProvider = loginProvider;
  setTimeout(() => form.submit(), 0);
}
5
  • Why don't you just add the needed data (provider) to the buttons and make them submit buttons? Commented Jun 21, 2020 at 16:22
  • what do you mean? can a button have a value for submission? Commented Jun 21, 2020 at 16:40
  • 1
    Yes this should be possible: <button type="submit" name="loginProvider" value="google">Log in using Google</button> Commented Jun 21, 2020 at 16:55
  • 1
    But when using angular a regular form submission might not be the best decision as it causes the page to reload. A post call to the backend via the HttpClient should usually be enough to obtain a new session and log the user in. Commented Jun 21, 2020 at 16:57
  • @JakobEm If you post this as an answer I'll accept Commented Jun 21, 2020 at 17:04

1 Answer 1

3

You can put the different values as form values to the submit buttons like this:

<form #form method="post" class="form-horizontal" [action]="loginUrl">
    <div>
        <p>
        <button ion-button block type="submit" name="loginProvider" value="StripeConnect" title="Log in using Stripe">
            Stripe Connect
        </button>
        <button ion-button block type="submit" name="loginProvider" value="google" title="Log in using Google">
            Google
        </button>
            <input type="text" name="entryCode" placeholder="Entry Code">
        </p>
    </div>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.