Angular 4 : ngNativeValidate is not allowed in Form - html

I'm using Angular 4 to build a form and required attribute is not working. I tried adding <form ngNativeValidate>...</form> as suggested by many answers but i got :
Attribute ngNativeValidate is not allowed here.
Here is my code :
<form #f="ngForm" (ngSubmit)="submit()" ngNativeValidate>
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input class="form-control" type="text" [(ngModel)] = "email" name='email' placeholder="Email" required/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-def btn-block">Submit</button>
</div>
</form>

try to replace this : <input class="form-control" type="text" [(ngModel)] = "email" name='email' placeholder="Email" required/>
with this : <input class="form-control" type="text" ngModel #email="ngModel" name='email' placeholder="Email" required/>
so all your code should look like this :
<form #f="ngForm" (ngSubmit)="submit()">
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input class="form-control" type="text" ngModel #email="ngModel" name='email' placeholder="Email" required/>
</div>
<div class="alert alert-danger" role="alert" *ngIf="!email.valid && email.touched" >
<span *ngIf="!email.valid"> This field is required</span>
</div>
<div class="form-group">
<button type="submit" class="btn btn-def btn-block">Submit</button>
</div>
</form>
Also remove the unnecessary ngNativeValidate and it should work now.

Related

required property of input field not working and input field color does not changed

<div class="container">
<h1>SignUp Form</h1>
<form>
<div class="form-group" >
<label for="name">Name</label>
<input type="text" class="form-control" [ngClass]="{'red-border':user.name.errors}" [(ngModel)]="user.name" [ngModelOptions]="{standalone: true}" id="name" required >
</div>
<div class="form-group">
<label for="pass">Password</label>
<input type="password" class="form-control" id="pass" [(ngModel)]="user.pass" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="cpass">Confirm Password</label>
<input type="password" class="form-control" id="cpass "required [(ngModel)]="user.cpass" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="dob">DOB</label>
<input type="date" class="form-control" id="dob" required [(ngModel)]="user.dob"[ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" required [(ngModel)]="user.email" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="contact">Contact</label>
<input type="text" class="form-control" id="contact" required [(ngModel)]="user.contact" [ngModelOptions]="{standalone: true}">
</div>
<button type="button" (click)="validateUser(user)" class="btn btn-success" >Submit</button>
</form>
</div>
I am new to angular 2, i had tried required property in input tag,but its not working. Also i want to change the color when input in wrong. I tried it but i don,t get it how to do it. Here is the code.
give name to your input field like name="name" and then try this user.name.errors.required instead of user.name.errors

Auto filled form in Chrome on iOS not valid with Angular 5

I have an Angular 5 app with a login form. On iOS version 11.3 with Chrome the form auto fills the email and password fields but the form fails validation.
However, this works fine in Safari on the same device.
It also works fine in all browsers on Android.
I have tried two different ways of creating the form and both have the same behavior.
Method 1
<ngx-loading [show]="isLoading"></ngx-loading>
<div class="row">
<div class="text-center col-12">
<h2 class="form-signin-heading">Please sign in</h2>
<form class="form-signin" [formGroup]="form" (ngSubmit)="submit()">
<div class="form-group">
<label class="sr-only" for="email">Email address</label>
<input autofocus class="form-control" id="email" name="email" maxlength="100" placeholder="Email address" type="email" formControlName="email">
<div *ngIf="form.controls.email.touched && form.controls.email.errors?.required" class="text-danger">Required</div>
</div>
<div class="form-group">
<label class="sr-only" for="password">Password</label>
<input class="form-control" id="password" name="password" maxlength="100" placeholder="Password" type="password" formControlName="password">
<div *ngIf="form.controls.password.touched && form.controls.password.errors?.required" class="text-danger">Required</div>
</div>
<button class="btn btn-lg btn-gold btn-block" type="submit" [disabled]="!form.valid || isLoading">Sign in</button>
</form>
</div>
</div>
Method 2
<ngx-loading [show]="isLoading"></ngx-loading>
<div class="row">
<div class="text-center col-12">
<h2 class="form-signin-heading">Please sign in</h2>
<form class="form-signin" name="form" (ngSubmit)="f.form.valid && submit()" #f="ngForm" novalidate>
<div class="form-group">
<label class="sr-only" for="email">Email address</label>
<input autofocus class="form-control" id="email" name="email" maxlength="100" placeholder="Email address" type="email" [(ngModel)]="model.email" #email="ngModel" required>
<div *ngIf="f.submitted && !email.valid" class="text-danger">Required</div>
</div>
<div class="form-group">
<label class="sr-only" for="password">Password</label>
<input class="form-control" id="password" name="password" maxlength="100" placeholder="Password" type="password" [(ngModel)]="model.password" #password="ngModel" required>
<div *ngIf="f.submitted && !password.valid" class="text-danger">Required</div>
</div>
<button class="btn btn-lg btn-gold btn-block" type="submit" [disabled]="isLoading">Sign in</button>
</form>
</div>
</div>

modal form not submitting

The problem is that when i click on the button nothing happens at all which it should be at least to me.
I don't need a direct answer. Just a hint, or a pointer of what can be going on.
Here is part of the code for the modal form
<div class="modal-body">
<form Method="POST" id="Signin-Form" role="form">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
<input name="txt_uname" id="txt" type="text" class="form-control input-lg" placeholder="Enter User Name" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div>
<input name="txt_umail" id="email" type="text" class="form-control input-lg" placeholder="Enter Email" required data-parsley-type="email" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
<input name="txt_upass" id="pass1" type="password" class="form-control input-lg" placeholder="Enter Password" required data-parsley-length="[6, 10]" data-parsley-trigger="keyup" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
<input name="txt_upass2" id="pass2" type="password" class="form-control input-lg" placeholder="Confirm Password" required data-parsley-length="[6, 10]" data-parsley-trigger="keyup" />
</div>
</div>
<button type="submit" class="btn btn-success btn-block btn-lg"><i class="glyphicon glyphicon-open-file">CREATE ACCOUNT!</i></button>
</form>
You need to add action attribute to the form to be able to send the form-data when the form is submitted.
Sample code below
<form action="submittedpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
After you click submit button, the form data is sent for processing to a PHP file named "submittedpage.php". The form data is sent with the HTTP POST method.
To display the submitted data you could simply echo all the variables. The "submittedpage.php" see the code below:
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
You can see this link for more info in form handling.
https://www.w3schools.com/php/php_forms.asp
Hope this helps.

Fetching inputted form data in modal of different page

I have created a register form inside a modal of index page , when user submit it, user gets directed to 2nd page which is confirmation through PHP.
If users gets an error it is necessary to go back to previous page and fill the whole form again, how can i save the values inputted by user recently and when he gets redirected to previous page he see the form but filled of his recent values
<div class="modal fade" id="registermodal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"> x </span><span class="sr-only">Close</span></button>
<h3 class="modal-title text-center" id="lineModalLabel"> Register </h3>
</div>
<div class="modal-body">
<!-- content goes here -->
<form action="confirmation.php" method="POST" enctype="multipart/form-data">
<div id="cfirstname" class="form-group" style="float:left;width:45%;">
<label for="firstname"> First Name </label>
<input oninvalid="this.setCustomValidity('Please enter your first name')" oninput="setCustomValidity('')" required type="text" class="form-control" id="firstname" name="firstname" placeholder="First name" autocomplete="off">
</div>
<div id="clastname" class="form-group" style="float:right;width:45%;">
<label for="lastname"> Last Name </label>
<input oninvalid="this.setCustomValidity('Please enter your last name')" oninput="setCustomValidity('')" required type="text" class="form-control" id="lastname" name="lastname" placeholder="Last name" autocomplete="off">
</div>
<div id="cemail" class="form-group" style="clear:both;">
<label for="email"> Email </label>
<input oninvalid="this.setCustomValidity('Please enter your email name')" oninput="setCustomValidity('')" required type="email" class="form-control" id="email" name="email" placeholder="Email" autocomplete="off">
</div>
<div id="ccategory" class="form-group" style="clear:both;">
<label for="category"> Category </label>
<input oninvalid="this.setCustomValidity('Category is Required')" oninput="setCustomValidity('')" required type="text" class="form-control" id="category" name="category" placeholder="Category" autocomplete="off"> <span class="help">Enter the category you are expert in </span>
</div>
<div class="form-group ">
<label for="Password"> Password </label>
<input oninvalid="this.setCustomValidity('Please enter a password)" oninput="setCustomValidity('')" required type="password" class="form-control" name="rpassword" id="password" placeholder="Password" autocomplete="off">
<span id="8char" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> 8 Characters Long<br>
</div>
<div class="form-group ">
<label for="Password">Confirm Password </label>
<input oninvalid="this.setCustomValidity('Please confirm your password')" oninput="setCustomValidity('')" required type="password" class="form-control" name="rcpassword" id="cpassword" placeholder="Repeat Password" autocomplete="off">
<span id="pwmatch" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Passwords Match
</div>
<div id="cfblink" class="form-group">
<label for="fblink"> Facebook profile link </label>
<input type="text" class="form-control" id="fblink" name="fblink" placeholder="Facebook Link" autocomplete="off">
</div>
<div class="form-group">
<label for="ppic">Please upload an image of yourself</label>
<input class="btn btn-default" required="required" type="file" name="file" id="file">
<span id="cppic" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Image uploaded
</div>
</div>
<div class="modal-footer">
<div class="btn-group btn-group-justified" role="group" aria-label="group button">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default" data-dismiss="modal" role="button">Close</button>
</div>
<div class="btn-group" role="group">
<button type="submit" id="signup" name="signup" class="btn btn-default btn-hover-green" role="button"> Proceed </button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
well i found answer myself just put the variable as value input tag
<input oninvalid="this.setCustomValidity('Please enter your first name')" oninput="setCustomValidity('')" required type="text" class="form-control" id="firstname" name="firstname" placeholder="First name" autocomplete="off" <?php echo 'value="'.$variable_name.'"'; ?> >

Why is my html form not sending to email or won't submit when I put code needed?

Here is the code to my form, if anyone has a way of fixing this that would be awesome.
<form id="rendered-form">
<div class="fb-text form-group field-name">
<label for="name" class="fb-text-label">Name <span class="required">*</span> </label>
<input type="text" required="" class="form-control name" name="name" id="name" aria-required="true"></div>
<div class="fb-email form-group field-email">
<label for="email" class="fb-email-label">Email <span class="required">*</span> </label>
<input type="email" required="" class="form-control email" name="email" id="email" aria-required="true"></div>
<div class="fb-text form-group field-phone">
<label for="phone" class="fb-text-label">Phone Number </label>
<input type="text" class="form-control phone" name="phone" id="phone"></div><div class="fb-undefined form-group field-message">
<label for="message" class="fb-textarea-label">Message <span class="required">*</span> </label>
<textarea type="textarea" required="" rows="5" class="form-control message" name="message" id="message" aria-required="true"></textarea></div>
<div class="fb-submit form-group field-button-1480832953294"><button type="submit" class="button-input btn btn-warning" name="button-1480832953294" style="warning" id="button-1480832953294">CONTACT US</button></div></form>
</div>
Here is the new code, I have just updated it and it still doesnt work.
<div data-form-alert="true">
<div hidden="" data-form-alert-success="true" class="alert alert-form alert-success text-xs-center">We will contact you as soon as possible!</div>
</div>
<form id="rendered-form" action="mailto:zach#ztmartin.net" method="post">
<div class="fb-text form-group field-name">
<label for="name" class="fb-text-label">Name <span class="required">*</span> </label>
<input type="text" required="" class="form-control name" name="name" id="name" aria-required="true"></div>
<div class="fb-email form-group field-email">
<label for="email" class="fb-email-label">Email <span class="required">*</span> </label>
<input type="email" required="" class="form-control email" name="email" id="email" aria-required="true"></div>
<div class="fb-text form-group field-phone">
<label for="phone" class="fb-text-label">Phone Number </label>
<input type="text" class="form-control phone" name="phone" id="phone"></div>
<div class="fb-undefined form-group field-message">
<label for="message" class="fb-textarea-label">Message <span class="required">*</span> </label>
<textarea type="textarea" required="" rows="5" class="form-control message" name="message" id="message" aria-required="true"></textarea>
</div>
<div class="fb-submit form-group field-button-1480832953294">
<button type="submit" class="btn btn-primary">CONTACT US</button>
</div>
</form>
You should send your form through an action
<form action="example.php" method="post">
It doesn't have to be PHP, but it is an example for how to make an action attribute.
For posting data, you should put method="post" in your form tag, as in
<form method="post">
...
</form>
The default method is get.
The action attribute is not needed if your post url is the same as the current url. in fact, by not putting anything in your form tag, and assuming your page is found at http://myhost.com/mypage, you're actually using the equivalent of this:
<form action="http://myhost.com/mypage" method="get">
...
</form>