hi i have a sign up form , it has six input fields
html code
<div id="signup">
<form id="suform" method="POST" action="signup/newUser">
<p>
<label>Frist Name</label>
<input type="text" name="fName"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Last Name</label>
<input type="text" name="lName"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Email</label>
<input type="text" name="Email"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Mobile Number</label>
<input type="text" name="MNumber"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Password</label>
<input type="password" name="Password"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Re Password</label>
<input type="password" name="RePassword"/>
<span class="errorMessage"></span>
</p>
<p>
<input type="submit" class="button" value="sign up"/>
</p>
</form>
</div>
when the user clicked sign up button , first i ensure that no input fields is empty , if i found any input fields in empty then i print an error message left to that input field ,
jquery code
$(document).ready(function(){
$('#suform').on('submit', function(e){
e.preventDefault();
var errorCount = 0;
$('span.errorMessage').text(''); // reset all error mesaage
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
if(errorCount === 0){
$(this)[0].submit(); // submit form if no error
}
});
});
i want the user to input his password twice to ensure that he saves it
my question is how to check the two passwords input fields if they are equal or not , and if not i want to print a message error to the left of that two input fields
code
Checking the fields and showing an error without jQuery:
if (document.forms[0].Password.value != document.forms[0].RePassword.value) {
document.forms[0].Password.parentNode.getElementsByClassName("errorMessage")[0].innerHTML="Passwords aren't the same!";
document.forms[0].RePassword.parentNode.getElementsByClassName("errorMessage")[0].innerHTML="Passwords aren't the same!";
}
If there is more than one form on the page (even just a search form) you'll need to adjust document.forms[0] accordingly.
To use this code in your form, add onsubmit="return checkForm();" to the form tag, like:
<form id="suform" method="POST" action="signup/newUser" onsubmit="return checkForm();">
Then, in your script tag, create the function checkCode which will return false (in other words stop form submission) if there's a problem:
<script type="text/javascript">
<!--
function checkCode() {
if (document.forms[0].Password.value != document.forms[0].RePassword.value) {
document.forms[0].Password.parentNode.getElementsByClassName("errorMessage")[0].innerHTML="Passwords aren't the same!";
document.forms[0].RePassword.parentNode.getElementsByClassName("errorMessage")[0].innerHTML="Passwords aren't the same!";
return false;
}
}
//-->
</script>
Well this might work i suppose.,
var password= $('input[name="Password"]').val();
var repass= $('input[name="RePassword"]').val();
if(password!=repass){
var error = 'Password not matching';
$('input[name="RePassword"]').next('span').text(error);
$('input[name="Password"]').next('span').text(error);
errorCount = errorCount + 1;
}else if(password=="" || repass==""){
if(password==""){
var error = 'Please enter a password.';
$('input[name="Password"]').next('span').text(error)
errorCount = errorCount + 1;
}else{
var error = 'Please enter a repassword.';
$('input[name="RePassword"]').next('span').text(error)
errorCount = errorCount + 1;
}
}
}else{
continue;
}
You can do it like that:
var pass1 = $('input[name=Password]').val();
var pass2 = $('input[name=RePassword]').val();
if(pass1 != '' && pass1 != pass2) {
//show error
var error = 'Password confirmation doesn\'t match.';
$('input[name=Password]').next('span').text(error);
$('input[name=RePassword]').next('span').text(error);
errorCount = errorCount + 1;
}
The "for" property in the label is used as follows:
<label for="myPasswordField">
<input type="password" id="myPasswordField" name="Password" />
</label>
So when you click on the label this will set the focus on the related element with that ID attribute.
To check if the phone field is a number you need that:
var mobile = $('input[name=MNumber]').val();
if(isNaN(parseFloat(mobile )) && !isFinite(mobile )) {
var error = 'Mobile number incorect.';
$('input[name=MNumber]').next('span').text(error);
errorCount = errorCount + 1;
}
<p>
<label>Password</label>
<input type="password" name="Password"/>
<span class="errorMessage"></span>
</p>
<p>
<label>Re Password</label>
<input type="password" name="RePassword"/>
<span class="errorMessage"></span>
</p>
if ( $("input[type=password][name='Password']").val() == $("input[type=text][name='RePassword']").val(){
//Do this
}
Something like this? http://jsfiddle.net/K5CMC/
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}else if($this.attr('id') === 'Password'){
//compare the two fields
if($('#Password').val() !== $('#RePassword')){
//they don't match, do stuff
}
}
You can do it like this Demo on JsFiddle
$(document).ready(function(){
$('#suform').on('submit', function(e){
e.preventDefault();
var errorCount = 0;
$('span.errorMessage').text(''); // reset all error mesaage
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}
else
if($(this).attr('name') == "RePassword")
if($('input[name=Password]').val() != $(this).val())
alert("must have same password");
});
if(errorCount === 0){
$(this)[0].submit(); // submit form if no error
}
});
});
$(document).ready(function(){
$('#suform').on('submit', function(e){
e.preventDefault();
var errorCount = 0;
$('span.errorMessage').text(''); // reset all error mesaage
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
if($('input[name="Password"]').val() != $('input[name="RePassword"]').val())
{
var error = 'Password not match'; // take the input field from label
$('input[name="RePassword"]').next('span').text(error);
errorCount = errorCount + 1;
}
if(errorCount === 0){
$(this)[0].submit(); // submit form if no error
}
});
});
Related
I have this query
$tww_update_sql = "UPDATE `telesales_anc` SET
`Ime` = '".$_POST['Ime'];
and I have a form with submit button as follows:
<form id="contact" method="post" action="ANC_pozivanje_test.php">
<div class="col-md-2 col-sm-12 col-xs-12 form-group">
<small>Ime</small>
<input id="contact_name" type="text" name="Ime" placeholder="Ime" class="form-control" value="<?php echo $values['Ime']?>">
</div>
<div class="form-group">
<div id="contact_submit" class="col-md-9 col-sm-9 col-xs-12">
<button type="submit" class="btn btn-success" value="Save">Save</button>
</div>
</div>
Script that I used for checking in field is populated is as follows:
<script>
$(document).ready(function() {
<!-- Real-time Validation -->
<!--Name can't be blank-->
$('#contact_name').on('input', function() {
var input=$(this);
var is_name=input.val();
if(is_name){input.removeClass("invalid").addClass("valid");}
else{input.removeClass("valid").addClass("invalid");}
});
<!-- After Form Submitted Validation-->
$("#contact_submit button").click(function(event){
var form_data=$("#contact_name").serializeArray();
var error_free=true;
for (var input in form_data){
var element=$("#contact_name"+form_data[input]['']);
var valid=element.hasClass("valid");
var error_element=$("span", element.parent());
if (!valid){
error_element.removeClass("error").addClass("error_show");
error_free=false;
}
else{
error_element.removeClass("error_show").addClass("error");
}
}
if (!error_free){
event.preventDefault();
}
else{
alert('Status nije popunjen');
}
});
});
</script>
Problem is when button is submitted (if field is not populated) I got message "Status nije popunjen" but form is submited regard message.
Is it necessary to use script for this?
It seems you check whether error_free is false, in which case you prevent for submission, however, if it is true (so if the field is populated), you only give an alert. Shouldn't event.preventDefault() be inside else?
You should not listen to button.click, but to form.submit.
<!-- After Form Submitted Validation-->
$("#contact").on('submit', function(event) {
The method event.preventDefault() will prevent the form from submitting, and should be in the same block as the alert()
if (!error_free) {
event.preventDefault();
alert('Status nije popunjen');
}
all you want to do is to validate the data on the client side, making sure that a valid name is supplied. i will recreate this here.
You can simply make changes to it. but i believe this solves your need. Also note that you should validate data on the server. dont just rely on client side validation
$update_sql = "UPDATE " . $table_name . " SET Ime = '" . $_POST['txt-name'] . "'";
'use strict';
$(document).ready(function() {
//bind click event on the button
var form = document.forms['frm-contact'];
$('#btn-contact').bind('click', function(event) {
event.preventDefault(); //this will prevent the form from getting submitted, so that we can validate the user name.
var field = form.elements['txt-name'],
name = field.value,
len = name.length,
error = '';
if (len === 0) {
error = 'Enter your name';
}
else if (len < 2) {
error = 'name should not be less than 2 characters';
}
else if (len > 36) {
error = 'name should not exceed 36 characters';
}
else if (/^[^a-z]+/i.test(name)) {
error = 'name must start with letters';
}
else if (!/^['.a-z\- ]+$/i.test(name)) {
error = 'invalid characters found'; // name should contain only alphabets, dash character, space character and dot character only
}
//done validating. show error now or submit the form.
if (error) {
alert(error);
$(field).addClass('error');
}
else {
$(field).removeClass('error');
form.submit();
}
});
});
.error {
background-color: red;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="frm-contact" id="frm-contact" method="post" action="example.php">
<div class="form-group">
<label for="txt-name">Name:</label>
<input type="text" name="txt-name" id="txt-name" placeholder="enter your name" value="" />
</div>
<div class="text-center">
<button type="submit" class="btn btn-success" name="btn-contact" id="btn-contact" value="contact us">SEND</button>
</div>
</form>
I have written a html form and jquery to perform the validations. But when i click the submit button, nothing is happening. I can't understand what is going on, whether the form is linking up with the jquery file or not. Please any check my code and help me.
index.html
<html>
<head>
<title>validation</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
</head>
<body>
<form action="" method="post" id="reg_form">
<p>Name:</p>
<p><input id="name" name="name" type="text"></p>
<p>What's your name?</p>
<p>Email:</p>
<p><input id="email" name="email" type="text"></p>
<p>Enter mail id</p>
<p>Password:</p>
<p><input id="pass1" name="pass1" type="password"></p>
<p>More than 8 characters</p>
<p>Password:</p>
<p><input id="pass2" name="pass2" type="password"></p>
<p>same as above</p>
<p>phone</p>
<p><input id="phone" name="phone" type="text"></p>
<p>What's your number?</p>
<input id="submit" name="submit" type="submit" value="submit"/>
</form>
</body>
</html>
custom.js
$(document).ready(function(){
var form = $("#reg_form");
var name = $("#name");
var nameDetails = $("#nameDetails");
var email = $("#email");
var emailDetails = $("#emailDetails");
var pass1 = $("#pass1");
var pass2 = $("#pass2");
var pass1Details = $("#pass1Details");
var pass2Details = $("#pass2Details");
var phone = $("#phone");
var phoneDetails = $("#phoneDetails");
var button = $("#submit");
name.blur(validateName);
email.blur(validateEmail);
pass1.blur(validatePass1);
pass2.blur(validatePass2);
phone.blur(validatePhone);
name.keyup(validateName);
email.keyup(validateEmail);
pass1.keyup(validatePass1);
pass2.keyup(validatePass2);
phone.keyup(validatePhone);
form.submit(function(){
if(validateName() & validateEmail & validatePass1 & validatePass2() & validatePhone()){
return true;
}else{
return false;
}
});
function validateName(){
if(name.val().length<5){
name.addClass("error");
nameDetails.text("Your name should have atleast 5 characters");
nameInfo.addClass("error");
return false;
}else{
name.removeClass("error");
nameDetails.text("Whats your name?");
}
}
function validateEmail(){
var a = $("#email").val();
var regexp = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-za-zA-Z0-9_-]+#[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
if(filter.text(a)){
email.removeClass("error");
emailDetails.text("Enter mail id");
emailDetails.removeClass("error");
return true;
}else{
email.addClass("error");
emailDetails.text("Enter valid mail id");
emailDetails.addClass("error");
}
}
function validatePass1(){
if(pass1.val().length<8){
pass1.addClass("error");
pass1Details.text("8 characters or more");
pass1Details.addClass("error");
return false;
}else{
pass1.removeClass("error");
pass1.Details.text("Enter mail id");
pass1.Details.removeClass("error");
return true;
}
}
function validatePass2(){
if(pass2.val().length < 1){
pass2.addClass("error");
pass2Details.text("8 characters or more");
pass2Details.addClass("error");
return false;
}
if(pass1.val()!== pass2.val()){
pass2.addClass("error");
pass2Details.text("8 characters or more");
pass2Details.addClass("error");
return false;
}else{
pass2.removeClass("error");
pass2.Details.text("Same as above");
pass2.Details.removeClass("error");
return true;
}
}
function validatePhone(){
var b = $("#phone").val();
var regexp = /[0-9]{10}/;
if(filter.text(b)){
email.removeClass("error");
emailDetails.text("Enter phone number");
emailDetails.removeClass("error");
return true;
}else{
email.addClass("error");
emailDetails.text("Enter valid phone number");
emailDetails.addClass("error");
}
}
});
use the statements like this,
var name = $("#name ").val();
Or
var name = jQuery("#name ").val();
and then try...it will work...
Try this
$(document).ready(function(){
var form = $("#reg_form").val();
var name = $("#name").val();
...
});
Try this..
$(document).ready(function(){
var name = $("#name").val();
var nameDetails = $("#nameDetails").val();
var email = $("#email").val();
var emailDetails = $("#emailDetails").val();
var pass1 = $("#pass1").val();
var pass2 = $("#pass2").val();
var pass1Details = $("#pass1Details").val();
var pass2Details = $("#pass2Details").val();
var phone = $("#phone").val();
var phoneDetails = $("#phoneDetails").val();
});
I'm doing a register form for sending to database. However, there are two inputs of password, first is normal password and another one is to confirm password. Well, I can make jQuery to show when a user type a password which doesn't match with normal password, it will show red warning like PASSWORD NOT MATCH. Even though the passwords don't match, but a user can click a button to send a form into database successfully. How to stop a user from sending a form when the password don't match?
HTML is here.
<form id="myForm" action="registerAction" name="register" method="POST">
<p> <label class="inputField" > Password : </label> </p>
<p> <input class="registerField" id="textpwd" name="pwd" required="required" type="password" placeholder="Your password"/> </p>
<p> <label class="inputField" > Confirmation Password : </label> </p>
<p> <input class="registerField" id="textcfmpwd" name="mpwd" onChange="checkPasswordMatch();"required="required" type="password" placeholder="Confirmation password"/> <span class="warning" id="pwdWarning"> </span> </p>
<p> <input class="registerButton" type="submit" value="REGISTER"> </p>
</form>
Well, to show error like PASSWORD NOT MATCH is below.
function checkPasswordMatch() {
var password = $("#textpwd").val();
var confirmPassword = $("#textcfmpwd").val();
if (password != confirmPassword)
$("#pwdWarning").html("Passwords do not match!").css('color', 'red');
else
$("#pwdWarning").html("Passwords match.").css('color', 'green');
}
$(document).ready(function () {
$("#textcfmpwd").keyup(checkPasswordMatch);
});
In conclusion, how to stop a user from sending a form when the password don't match? Any ideas?
You can try this
$('#myForm').submit(function(e){
var bool = validatePassword();
if(!bool)
e.preventDefault(); // will stop the form from submitting
else
return true; //continue to submit form
});
Then for the validatePassword function
function validatePassword(){
var password = $("#textpwd").val();
var confirmPassword = $("#textcfmpwd").val();
if (password != confirmPassword){
$("#pwdWarning").html("Passwords do not match!").css('color', 'red');
return false;
}
else{
$("#pwdWarning").html("Passwords match.").css('color', 'green');
return true;
}
}
As it is at the moment, you'll need a bit of code duplication.
$('#myForm').submit(function(evt) {
var password = $("#textpwd").val();
var confirmPassword = $("#textcfmpwd").val();
if (password != confirmPassword){
evt.preventDefault();
}
});
A better solution is to refactor your checkPasswordMatch a bit, to have it return true or false, and work with that.
function passwordsMatch(){
return $('#textpwd').val() == $('#textcfmpwd').val();
}
$(document).ready(function () {
$("#textcfmpwd").keyup(function(){
if(!passwordsMatch()){
$("#pwdWarning").html("Passwords do not match!").css('color', 'red');
} else {
$("#pwdWarning").html("Passwords match.").css('color', 'green');
}
});
$('#myForm').submit(function(evt) {
if(!passwordsMatch()){
evt.preventDefault();
}
});
});
Note that this is only client-side scripting - you should do the same check server-side (PHP/C#/whatever).
I am building a sign up form, and want to include it into a div on the main page. The main page also includes a 'log in' form.
Both forms are included on the page using php include commands in the appropriate div i.e:
<?php include_once("login.php")?>
<?php include_once("signup.php")?>
Now when I use ajax on the second form i.e. the signup.php form, it sends back information from the fields in the first form. It doesn't help that they are both email and password fields.
Does anyone know how I can isolate the information from each form so i can send the data from each form separately? Below is all the relevant code for the forms and the Javascript.
Here is the code for the first form(login.php):
<form name="loginform" id="loginform" onsubmit="return false;">
<input style="margin-bottom:5px;" id="email" type="text" class="searchbox" onblur="checkusername()" maxlength="35" value="Email">
<span id="emailstatus"></span>
<input id="password" class="searchbox" type="password" onfocus="emptyElement('status')" maxlength="88" value="Password">
<p>Log In / <a href="#" onclick="forgotpass()">Forgot Password</p>
<span id="status"></span>
</form>
and the ajax for it:
function login(){
//isolate the variables from the form
var p = _("password").value;
var e = _("email").value;
var status = _("status");
if(e != "Email" && p != "Password"){
_("loginbtn").style.display = "none";
status.innerHTML = 'please wait ...';
//start the Ajax Request
var ajax = ajaxObj("POST", "login.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == "login_failed"){
status.innerHTML = 'There was a problem. Please check your email and password and try again. ';
_("loginbtn").style.display = "block";
} else {
window.location = "user.php?id="+ajax.responseText;
}
}
}
//data being sent by the ajax call
ajax.send("e="+e+"&p="+p);
} else {
status.innerHTML = "You're missing something..";
}
}
function emptyElement(x){
//The _(x) function is a shortcut for getElementById
_(x).innerHTML = "";
}
//This jQuery used to pre populate the email and password fields with "email" and "password"
$('input .seachbox').each(function(){
$(this)
.data('default', $(this).val())
.focus(function(){
if ($(this).val() == $(this).data('default')||''){
$(this).val() = ''
}
})
.blur(function(){
var default_val = $(this).data('default');
if($(this).val() == ''){
$(this).val($(this).data('default'))
}
});
});
and the second form(signup.php):
<form name="signupform" id="signupform" onsubmit="return false;">
<div>Email Address:</div>
<input id="emails" type="text" class="searchbox" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
<div>Create Password:</div>
<input id="pass1" type="password" class="searchbox" onfocus="emptyElement('status')" maxlength="16">
<div>Confirm Password:</div>
<input id="pass2" type="password" class="searchbox" onfocus="emptyElement('status')" maxlength="16">
</form>
<br> Create Account<p>
<div class="statuserror"><span id="status" >This is a permanent error</span></div>
</div>
and the ajax for it:
function signup(){
var e = _("email").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var status = _("status");
if( e == "" || p1 == "" || p2 == ""){
status.innerHTML = "Fill out all of the form data";
} else if(p1 != p2){
status.innerHTML = "Your password fields do not match";
} else {
status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText != "OK"){
status.innerHTML = ajax.responseText;
_("signupbtn").style.display = "block";
} else {
_("p1").innerHTML = "Please check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
}
}
}
ajax.send("e="+e+"&p="+p1);
}
EDIT - SOLUTION:- Have - after 3 days found a solution so stupid i had to share it. Basically I changed the id of the status div from "status" to "status1" and found that everything is working fine now. I think that it might be because on the login page I also have a div named status so the browser is unsure which div to put it in and just does nothing. This also explains why the signup.php page works when run alone in the browser but not when the login.php is included along with it in the main page.
Moral of the story - MAKE SURE YOUR IDS ARE ALL DIFFERENT!!
Thanks to everyone for the help.
The contact form it´s working, if you fill it all it sends the message. The problem if you don´t fill in the email box, the form doesn´t alert you about it, is there anyway that I can show a word or somekind of alert to the user?
this is my markup:
<div class="form">
<h2>ESCRIBENOS</h2>
<form method="post" action="process.php">
<div class="element">
<label>Nombre (obligatorio):</label><br/>
<input type="text" name="name" class="text" />
</div>
<div class="element">
<label>Email (obligatorio):</label><br/>
<input type="text" name="email" class="text" />
</div>
<div class="element">
<label>Telefono:</label><br/>
<input type="text" name="website" class="text" />
</div>
<div class="element">
<label>Mensaje:</label><br/>
<textarea name="comment" class="text textarea" /></textarea>
</div>
<div class="element">
<input type="submit" id="submit"/>
<div class="loading"></div>
</div>
</form>
</div>
And this is my script:
$(document).ready(function() {
//if submit button is clicked
$('#submit').click(function () {
//Get the data from all the fields
var name = $('input[name=name]');
var email = $('input[name=email]');
var website = $('input[name=website]');
var comment = $('textarea[name=comment]');
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
if (name.val()=='') {
name.addClass('hightlight');
return false;
} else name.removeClass('hightlight');
if (email.val()=='') {
email.addClass('hightlight');
return false;
} else email.removeClass('hightlight');
if (comment.val()=='') {
comment.addClass('hightlight');
return false;
} else comment.removeClass('hightlight');
//organize the data properly
var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' +
website.val() + '&comment=' + encodeURIComponent(comment.val());
//disabled all the text fields
$('.text').attr('disabled','true');
//show the loading sign
$('.loading').show();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "../process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.form').fadeOut('slow');
//show the success message
$('.done').fadeIn('slow');
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, unexpected error. Please try again later.');
}
});
//cancel the submit button default behaviours
return false;
});
});
Can someone help me out please?
Try this:
var name = $('input[name=name]');
var email = $('input[name=email]');
var website = $('input[name=website]');
var comment = $('textarea[name=comment]');
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
$('input[type=text]').each(function(){
if($(this).val().length == 0){
$(this).addClass('hightlight');
alert('Empty input field')
return false;
}
});
.... rest of your code
Note: This does not work for textarea but I think you can figure that out yourself!
EDIT:
var valid = false;
$('input[type=text]').each(function(){
if($(this).val().length == 0){
$(this).addClass('hightlight');
alert('Empty input field')
valid = false;
}else{
valid = true;
}
});
if(valid == false) return;
console.log('All input fields are filled in..');
... rest of your code. You can remove al the if else statements for input fields. For checking the textarea you could give all fields the same class and do:
$('form.classofallelements').each(function(){