Skip to content

Instantly share code, notes, and snippets.

@vorpal56
Last active September 30, 2020 14:30
Show Gist options
  • Save vorpal56/c5438234f40df7578e6ded4f80054938 to your computer and use it in GitHub Desktop.
Save vorpal56/c5438234f40df7578e6ded4f80054938 to your computer and use it in GitHub Desktop.
Contact form without a server using Angular - contact.component.html with Material
<form class="contact" [formGroup]="form" method="post" (ngSubmit)="onSubmit()">
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput [formControl]="name" required>
<mat-error *ngIf="name.invalid">Please enter your name</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Email</mat-label>
<input matInput [formControl]="email" placeholder="email@example.com" required>
<mat-error *ngIf="email.invalid">Please enter a valid email</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Message</mat-label>
<textarea matInput [formControl]="message" maxlength="256" placeholder="I'm interested in..." required></textarea>
<mat-hint align="end"> {{message.value?.length || 0}}/256</mat-hint>
<mat-error *ngIf="message.invalid">Please enter a message</mat-error>
</mat-form-field>
<button [disabled]="isLoading" class="submit" type="submit">Submit</button>
<input [formControl]="honeypot" class="hidden" type="text" />
<div [ngClass]="!submitted? 'hidden' : 'visible'" class="center-text">
<span>{{responseMessage}}</span>
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment