My form is tripping up with required fields are able to be submitted without entering anything in the field. I'd like to use placeholder text but it must be reading this as a value, hence the form goes through?
I'm using the html 5 'placeholder' and 'required attributes. email address does get flagged as the placeholder text doesnt match the format i think.
Is there any way to get the form to flag the other required fields?
<form action="FormToEmail.php" method="POST" name="Competition">
<div id="text">
<input class="field" value="" type="text" name="Name" required placeholder="FULL NAME*">
<input class="field" value="" type="email" name="Email" required placeholder="EMAIL ADDRESS*">
<input class="field" value="" type="text" name="Contact-number" required placeholder="CONTACT NUMBER*">
<input class="field" value="" type="text" name="Code" required placeholder="UNIQUE CODE*">
<p>I have read the Terms and Conditions</p><input type="checkbox" name="Terms and Conditions" value="Selected" required></div>
<p >Read the Terms and Conditions.</p>
<p>* required field</p>
<input class="btn btn-draw" type="submit" name="submit" value="Submit!" />
</form>
EDIT: i recall now that i'm using the javascript below to show the placeholder text in older versions of internet explorer. This script does work for that with the knock on effect of the empty fields submitting.
I am probably best covered to leave it like this, but i'd be interested if there is any comprehensive solution to ensure placeholder text shows in older browsers and the empty fields are flagged.
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
Ok, you need to prevent the form submit if the input val is equal the placeholder:
}).blur().parents('form').submit(function(event) {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() === input.attr('placeholder')) {
event.preventDefault();
input.val('');
}
Are you using any plugin? In which browser is the problem?
The test don't show any problems.
https://jsfiddle.net/mcymnayz/
<form action="FormToEmail.php" method="POST" name="Competition">
<div id="text">
<input class="field" value="" type="text" name="Name" required placeholder="FULL NAME*">
<input class="field" value="" type="email" name="Email" required placeholder="EMAIL ADDRESS*">
<input class="field" value="" type="text" name="Contact-number" required placeholder="CONTACT NUMBER*">
<input class="field" value="" type="text" name="Code" required placeholder="UNIQUE CODE*">
<p>I have read the Terms and Conditions</p><input type="checkbox" name="Terms and Conditions" value="Selected" required>
</div>
<p >Read the Terms and Conditions.</p>
<p>* required field</p>
<input class="btn btn-draw" type="submit" name="submit" value="Submit!" />
</form>
Related
I'm using this jQuery script to focus onto next input when enter pressed:
$(function() {
$(".form >input").on('keyup', function(e) {
if (e.which === 13) {
$(this).next('input').focus();
}
});
});
It does work with this basic skinny HTML form
<div class="form">
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
</div>
But not with this one
<div class="form">
<input name="cislo1" type="text" class=cislo1 placeholder="" id="cislo1" autofocus /><br>
<input name="cislo2" type="text" class=cislo2 placeholder="" id="cislo2" /><br>
<input name="cislo3" type="text" class=cislo3 placeholder="" id="cislo3" /><br>
<input name="cislo4" type="text" class=cislo4 placeholder="" id="cislo4" /><br>
<input name="cislo5" type="text" class=cislo5 placeholder="" id="cislo5" /><br>
<input name="cislo6" type="text" class=cislo6 placeholder="" id="cislo6" /><br>
<input name="cislo7" type="text" class=cislo7 placeholder="" id="cislo7" /><br>
<input name="cislo8" type="text" class=cislo8 placeholder="" id="cislo8" /><br>
<input name="cislo9" type="text" class=cislo9 placeholder="" id="cislo9" /><br>
<input name="cislo10" type="text" class=cislo10 placeholder="" id="cislo10" /><br>
<input name="cislo11" type="text" class=cislo11 placeholder="" id="cislo11" /><br>
</div>
What seems to be the problem here? Help me please, I'm stuck
The issue here is you are using direct child selector like:
$(".form > input")
This only matches any direct input element inside form class, but in your next example input is not the direct child. So, you need to descent sector instead like:
$(".form input")
This will match any input inside the form class where it is a direct child or not.
Also, you need to replace
$(this).next('input').focus();
with this:
$(this).nextAll('input:first').focus();
This is needed because .next() will get the immediately following sibling of each element, but here input is not the immediate sibling. We also have some <br> in between which are causing the issue. This can be resolved using .nextAll('input:first') instead.
Demo:
$(function() {
$(".form input").on('keyup', function(e) {
if (e.which === 13) {
$(this).nextAll('input:first').focus();
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form">
<p class="cislo">
<input name="cislo1" type="text" class=cislo1 placeholder="" id="cislo1" autofocus onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo1.value=cislo1.value.slice(0,2)" /><br>
<input name="cislo2" type="text" class=cislo2 placeholder="" id="cislo2" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo2.value=cislo2.value.slice(0,2)" /><br>
<input name="cislo3" type="text" class=cislo3 placeholder="" id="cislo3" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo3.value=cislo3.value.slice(0,2)" /><br>
<input name="cislo4" type="text" class=cislo4 placeholder="" id="cislo4" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" oninput="cislo4.value=cislo4.value.slice(0,2)" /><br>
</p>
</div>
I have input box with email address. It should not be auto complete but even after added autocomplete="off" in input box. Its showing auto complete values.
it is probably found in chrome...but you can try
in form tag add autocomplete="off" autocomplete="false" autofill="off"
and then add following code after form opens...
<input type="text" name="usernamefake" style="display:none;">
<input type="password" name="fakepassword" style="display:none;">
<!-- from here now your all input fields...below-->
If your problem doesn't get solve with above solution, you can add one more hidden fake input field just above your actual email input field and have a try...
Update :
you can try
<input type="text" name="email" readonly onfocus="if (this.hasAttribute('readonly')) {
this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
this.blur(); this.focus(); is for mobile screens to show keyboard after readonly attribute is removed..by js
EXAMPLE CODE :
div{
padding:10px;
margin:20px;
}
input {
padding:5px;
margin:5px;
}
<div>
<form autocomplete="off">
<label for="email">E-Mail</label>
<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
<br/>
<label for="pw">Password</label>
<input id="pw" readonly type="password" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
this.blur(); this.focus(); }" />
<br/>
<input type="submit" value="Go!" />
</form>
</div>
I'm trying to make a form in which the user enters an email and password and after clicking submit the page redirects to another page without saving or doing anything with email and password, but I want the form to check whether the entered value for email is valid and password field is not empty. Is it possible to do in HTML (just HTML)?
Here is what I have tried so far...
<form action="../../../redirect.html">
<input name="username" id="login-username" class="login-input pure-u-1 " type="text" maxlength="96" tabindex="1" aria-required="true"
value="" placeholder="Indtast din e-mail" title="Indtast din e-mail" autocorrect="off" spellcheck="false" autofocus>
<input name="password" id="login-password" class="login-input pure-u-1 " type="password" maxlength="96" tabindex="1" aria-required="true"
value="" placeholder="Indtast din adgangskode" title="Indtast din adgangskode" autocorrect="off" spellcheck="false" autofocus>
<button id="login-signing" class="pure-u-1 pure-button mbr-button-primary" type="submit" value="Submit" tabindex="1">Login</button>
</form>
In your input use required
exemple
Username: <input type="text" name="usrname" required>
From w3schools
Try using javascript email validation
<!DOCTYPE html>
<html>
<script>
function ValidateEmail()
{
if (/^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value))
{
return (true);
}
alert("Invalid Email");
return (false);
}
</script>
<form name=myForm action='demo_form.asp' onsubmit='return ValidateEmail();'>
<input type='text' name='email'>
<input type='submit'>
</form>
</html>
I am using Formspree (which is awesome) except: I have set all my fields to required, when I try manually I can't submit a form without filling everything properly, and however I still get a bunch of blank forms coming through. Has anybody experienced / fixed this before?
Thanks!
<form action="https://formspree.io/XXXXXXXX" method="post">
<input name="_gotcha" style="display: none" type="text">
<input class="form-control input-lg" name="firstname" placeholder="First Name" required type="text">
<input class="form-control input-lg" name="lastname" placeholder="Last name" required type="text">
<input class="form-control input-lg" name="phone" placeholder="Phone number" required type="text">
<select required name="country" class="form-control input-lg" style="border-radius:none; -webkit-appearance: none; padding-top:0px;">
<option value="" disabled selected>Please select your country </option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="other">Not in the List</option>
<!-- etc -->
</select>
<input type="hidden" name="referrer" id="referrer_field" />
<input type="hidden" name="url" id="url_field" />
<button id="demo" type="submit">GO</button>
And this is another Solution for your code, as this will work even if somebody put "spaces or leave it with blank" in the field of Name or Phone.
Check the Fiddle..
// Bind the event handler to the "submit" JavaScript event
$('form').submit(function () {
// Get the Login Name value and trim it
var fname = $.trim($('#fname').val());
var lname = $.trim($('#lname').val());
var phon =$.trim($('#phon').val());
// Check if empty of not
if (fname === '') {
alert('First name is empty.');
return false;
}
else if (lname === '') {
alert('Last Name is empty.');
return false;
}
else if (phon === '') {
alert('Phone is empty.');
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<form action="https://formspree.io/XXXXXXXX" method="post">
<input name="_gotcha" style="display: none" type="text">
<input class="form-control input-lg" name="firstname" placeholder="First Name" id="fname" required type="text">
<input class="form-control input-lg" name="lastname" placeholder="Last name" id="lname" required type="text">
<input class="form-control input-lg" name="phone" placeholder="Phone number" id="phon" required type="text">
<select name="country" class="form-control input-lg" style="border-radius:none; -webkit-appearance: none; padding-top:0px;">
<option value="" disabled selected>Please select your country </option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="other">Not in the List</option>
<!-- etc -->
</select>
<input type="hidden" name="referrer" id="referrer_field" />
<input type="hidden" name="url" id="url_field" />
<button id="demo" type="submit">GO</button>
If somebody type space to the input box then this Jquery code will work and ask him to fill proper text in fields.
Try W3Schools example of
http://www.w3schools.com/tags/att_input_required.asp
<input class="form-control input-lg" name="firstname" placeholder="First Name" required >
with no equals or anything
I thought the required tag was
required="True/false"
A simple solution would be something like this.
You can do this by using JQuery
// Bind the event handler to the "submit" JavaScript event
$('form').submit(function () {
// Get the Login Name value and trim it
var name = $.trim($('#log').val());
// Check if empty of not
if (name === '') {
alert('Text-field is empty. You cannot leave is blank!');
return false;
}
});
.text-label {
color: #cdcdcd;
font-weight: bold;
}
#pwd{
margin:10px 18px;
}
#logBtn{
margin:10px 90px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<form action="login.php" method="post">
<label>Login Name:</label>
<input type="text" name="email" id="log" />
<br/>
<label>Password:</label>
<input type="password" name="password" id="pwd" />
<br/>
<input type="submit" id="logBtn" name="submit" value="Login" />
</form>
I have simple html form on my site:
<form action="mailer.php" method="post">
<fieldset>
<div class="column-50">
<div>
<label for="name">Name <span>*</span></label>
<input type="text" id="name" name="name" required>
<span class="mf-error-message">Error! </span>
</div>
<div>
<label for="email">Email <span>*</span></label>
<input type="text" id="email" name="email" required>
<span class="mf-error-message">Error! </span>
</div>
.... // some more fields
<input type="submit" id="submit" name="submit" value="Enter your Information">
</form>
The problem is that on iOS devices ( phone, tablet .. ) form it can be submitted without user to populate required fields.
Why is that? Is there a way to fix it on client side?
This should work. But it will be for all not only for iOS
<form action="mailer.php" method="post" id="myForm">
Then this
var form = document.getElementById('myForm');
form.noValidate = true;
form.addEventListener('submit', function(event) {
if (!event.target.checkValidity()) {
event.preventDefault();
alert('Error! You must fill all required fields.');
}
}, false);