Angular 2 cdref detect changes is not working properly - html

This is my form for user or admin. This formed is saved to database using shared service. After clicking button toaster service is not opening. At first click form will be submitted but form not reseted and toaster service will not open.After doule click only toaster opens and form submitted with empty.
<form method="post" class="minimal" #customerForm=ngForm (submit)="addCustomer()" >
<label for="username">
Username:
<input type="text" name="username" id="username" [(ngModel)]="user.username" placeholder="Enter Username" required="required">
</label>
<label for="password">
Password:
<input type="password" name="password" id="password" [(ngModel)]="user.password" placeholder="Enter Password" required="required" />
</label>
<label for="isAdmin">
Admin:
<select class="admin" type="text" name="admin" [(ngModel)]="user.isAdmin" required>
<option>User</option>
<option>Admin</option>
</select>
</label>
<label for="email">
Email:
<input type="email" name="email" id="email" [(ngModel)]="user.emailId" placeholder="Enter Email" required="required" />
</label>
<label for="phone">
Phone No:
<input type="number" name="phone" id="phone" [(ngModel)]="user.phoneNo" placeholder="Enter Phone" required="required" />
</label>
<label for="dob">
Date of Birth:
<input type="date" name="date" id="date" [(ngModel)]="user.dob" placeholder="Enter Date" required="required" />
</label>
<button type="submit" class="btn btn-minimal btn-submit" [disabled]="!customerForm.form.valid">Create</button>
<toaster-container></toaster-container>
This is my ts file
addCustomer() {
console.log("user",this.user);
this.persistanceService.addUser(this.user).subscribe((result: User) => {
this.cdRef.detectChanges();
console.log("admin",this.user.isAdmin)
this.toast();
this.user = new User();
});

Related

html formular apple autofill doesn't work

I have a simple html formula with many input fields:
<input type="text" id="vorname" name="vorname" placeholder="Vorname" autocomplete="given-name" required>
<input type="text" id="nachname" name="nachname" placeholder="Nachname" autocomplete="family-name" required>
<input type="text" id="firma" name="firma" placeholder="Firma" autocomplete="organization">
<input type="text" id="strasse" name="strasse" placeholder="Straße" autocomplete="address-level2" required>
<input type="text" id="plz" name="plz" placeholder="PLZ" maxlength="5" pattern="[0-9]+" autocomplete="postal-code" required>
<input type="text" id="ort" name="ort" placeholder="Ort" autocomplete="street-address" required>
<input ype="email" id="email" name="email" placeholder="E-Mail" autocomplete="email" required>
<input type="tel" id="tel" name="tel" placeholder="Telefon" pattern="[0-9]+" autocomplete="tel" required>
If I call the website with my iPhone and I click on the first input "vorname" I get the option "Fill contact automatically".
All values will be filled automatically except "nachname","firma","Straße","PLZ"
On Safari (macOS) I get no option to filled any fields.
Where is my mistake?

registration form - browser is taking the wrong field as username

I have a registration form made by the following fields (extract from the code):
<form role="form" id="profile_form" class="contact-form" autocomplete="off">
<input type="text" name="mail" class="input-box form-control" autocomplete="off">
<input type="text" name="nome" class="input-box form-control" autocomplete="off">
<input type="text" name="cognome" class="input-box form-control" autocomplete="off">
<input type="password" name="password" id="password" placeholder="Password" class="input-box form-control" autocomplete="off">
<input type="password" name="verify_password" placeholder="Verifica password" class="input-box form-control" autocomplete="off">
</form>
Firefox is considering cognome field to be the username holder and so on form submitting it is asking to save the password as password (that's fine) and the cognome field as username.
What am I doing wrong here? How am I going to tell firefox to take the email as username?

Validating required input before onlick submit redirect

I am writing the following HTML code which requires certain input values and has a submit button which redirects to a different site when clicked. Currently the Submit button redirects even if no value is entered into the input boxes. I want the submit button to only work if all the input values are filled.
<!DOCTYPE html>
<html>
<body>
<h3>Please enter the following information</h3>
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="" required><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="" required><br>
<label for="email">Email:</label><br>
<input type="text" id="email" name="email" value="" required><br>
<label for="UserID">UserID:</label><br>
<input type="text" id="UserID" name="UserID" value="" required><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" value="" required><br><br>
<input onclick="window.location.href = 'https://example.site';" type="submit" value="Submit" />
</form>
</body>
</html>
The reason is because your submit isn't properly structured.
You see, if you replace your input submit with a button, it works perfectly:
<!DOCTYPE html>
<html>
<body>
<h3>Please enter the following information</h3>
<form action="https://example.site">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="" required><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="" required><br>
<label for="email">Email:</label><br>
<input type="text" id="email" name="email" value="" required><br>
<label for="UserID">UserID:</label><br>
<input type="text" id="UserID" name="UserID" value="" required><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" value="" required><br><br>
<button>Submit</button>
</form>
</body>
</html>
All you would have to change is add the link which you want it to redirect to in the action defined in the form.
This is the recommended method.
Keep in mind that you should always perform server-side checks regardless of whether there is a required attribute in the input field, as it can easily be removed.

Parameters of the request of a form not sent

I have a problem with this form, no matter which method I use (POST or GET), it doesn't send the request parameters email and pass.
<!DOCTYPE html>
<html>
<body>
<form action="controller/connect_user.php" method="GET">
<label for="email">Email:</label>
<input type="email" id="email" required>
<label for="pass">Password:</label>
<input type="password" id="pass" required>
<button type="submit">Connect</button>
</form>
</body>
</html>
The problem doesn't come from the adress in action, the file is well referenced.
I know I shouldn't use GET for sensitive data, but I used this method because it allows me to see easily the parameters in the URL.
Thank you for your help.
you need to use name attribute to pass data like this:
<form action="controller/connect_user.php" method="GET">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="pass">Password:</label>
<input type="password" id="pass" name="password" required>
<button type="submit">Connect</button>
instead of this:
<form action="controller/connect_user.php" method="GET">
<label for="email">Email:</label>
<input type="email" id="email" required>
<label for="pass">Password:</label>
<input type="password" id="pass" required>
<button type="submit">Connect</button>
</form>
After you can get thhose values like this:
$email = $_GET['email'];
$password = $_GET['password'];
I recommend to you to use POST instead of GET
You need to give your inputs a name:
<form action="controller/connect_user.php" method="GET">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="pass">Password:</label>
<input type="password" id="pass" name="password" required>
<button type="submit">Connect</button>
</form>
Then, in your PHP you can access them like:
echo $_POST['name'];
A input needs a name-attribute, otherwise there is no possiblity to get it (through GET or POST)
<input type="password" id="pass" name="pass" required>

After changing the default response from a required statement form doesn't behave normal

so after I made these changes the form won't accept any input. Meaning if I don't put in a first name it says 'Please enter first name". Works like it should. But if I put in a name it still says the same thing. It won't recognize I put in a name. Happens in each field and I have to refresh the page to make it work. Any ideas?
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="20" required oninvalid="this.setCustomValidity('Please Enter first name')"></input> </p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" required oninvalid="this.setCustomValidity('Please Enter last name')"></input>></p>
p>Email Address: <input type="text" name="email" size="20" maxlength="60" required oninvalid="this.setCustomValidity('Please Enter a valid email')"> </input>></p>
<p>Password: <input type="password" name="pass1" size="10" maxlength="20" required oninvalid="this.setCustomValidity('Please Enter a valid password')"> </input></p>
<p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" required></p>
<p><input type="submit" name="submit" value="Register" /></p>
</form>
You need to setCustomValidity('') to clear the invalidated state of the field.
You can see it work here
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" maxlength="20"
required oninvalid="this.setCustomValidity(this.willValidate?'':'Please Enter first name')"/></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" required oninvalid="this.setCustomValidity(this.willValidate?'':'Please Enter last name')"/></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="60" required oninvalid="this.setCustomValidity(this.willValidate?'':'Please Enter a valid email')"/></p>
<p>Password: <input type="password" name="pass1" size="10" maxlength="20" required oninvalid="this.setCustomValidity(this.willValidate?'':'Please Enter a valid password')"/> </p>
<p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" required /></p>
<p><input type="submit" name="submit" value="Register" /></p>
</form>