Ajax to PHP form submission. Keep getting "parsererror" - php

ajaxSubmit.js:
$(document).ready(function(){
$('#submit').click(function() {
$('#waiting').show(500);
$('#reg').hide(0);
$('#message').hide(0);
$.ajax({
type : 'POST',
url : 'post.php',
dataType : 'json',
data: {
login : $('input#login').val(),
pass : $('input#pass').val(),
pass1 : $('input#pass1').val()
},
success : function(data){
$('#waiting').hide(500);
$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
$('#reg').show(500);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$('#waiting').hide(500);
$('#message').removeClass().addClass('error')
.text(textStatus).show(500);
$('#reg').show(500);
}
});
return false;
});
});
HTML Form:
<div id="message" style="display: none;">
</div>
<div id="waiting" style="display: none;">
Please wait<br />
<img src="images/ajax-loader.gif" title="Loader" alt="Loader" />
<br />
</div>
<form id="reg" class="form with-margin" name="reg" method="post" action="">
<br />
<p class="inline-small-label">
<label for="login"><span class="big">Email</span></label>
<input type="text" name="login" id="login" value="">
</p>
<p class="inline-small-label">
<label for="pass"><span class="big">Password</span></label>
<input type="password" name="pass" id="pass" value="">
</p>
<p class="inline-small-label">
<label for="pass1"><span class="big">Password Again</span></label>
<input type="password" name="pass" id="pass1" value="">
</p>
<div align="center"><button type="submit" name="submit" id="submit" >Register</button></div>
</form>
<script type="text/javascript" src="js/ajaxSubmit.js"></script>
post.php:
<?php
sleep(3);
$login = $_POST['login'];
$pass = $_POST['pass'];
$pass1 = $_POST['pass1'];
$login = mysql_real_escape_string($login);
$pass = mysql_real_escape_string($pass);
$pass1 = mysql_real_escape_string($pass1);
if (empty($login)) {
$return['error'] = true;
$return['msg'] = 'You did not enter you email.';
}
else if (empty($pass)) {
$return['error'] = true;
$return['msg'] = 'You did not enter you password.';
}
else if ($test == false) {
$return['error'] = true;
$return['msg'] = 'Please enter a correct email. This will be verified';
}
else if (empty($pass)) {
$return['error'] = true;
$return['msg'] = 'You did not enter you password twice.';
}
else if ($pass != $pass1) {
$return['error'] = true;
$return['msg'] = 'Your passwords dont match.';
}
else {
$return['error'] = false;
$return['msg'] = 'Thanks! Please check your email for the verification code!';
}
echo json_encode($return);
?>
Any ideas why I keep getting the parsererror?

you have a $test variable else if ($test == false) that is undefined.
I'd suggest that if you are having parse errors through ajax, that you just load up the .php file manually and then php will point you to the line that the error is occurring on.

Related

jQuery Code Inside PHP File Being Displayed While Using AJAX

Whilst trying to use AJAX for validation on my website, it is completely displaying to the user with exception of the PHP variables, the jquery code I am using for styling my inputs. I am trying to change the styles of my inputs accordingly and provide and error message, which is successful, however, the javascript code is also being displayed
index.php
<html>
<head>
<link rel="stylesheet" href="css/template.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="jquery/template.js"></script>
<script type="text/javascript" src="jquery/index.js"></script>
</head>
<body onload="startUp();">
<!-- Banner Image -->
<div id="banner"><img id="bannerImage" src="abcdefd.com.jpg" alt=""></div>
<!-- Body Wrapper -->
<div id="wrapper">
<!-- Content -->
<div id="content">
<!-- <h2 id="title">Log In</h2> -->
<form id="loginForm" method="post" action="config/config.index.php">
<input type="text" name="email" id="email" placeholder="Email">
<input type="password" name="password" id="password" placeholder="Password">
<input class="click" type="submit" name="submit" id="submit" value="Log in">
</form>
<p id="err"></p>
</div>
</div>
</body>
</html>
index.js
$(document).ready(function(){
$("#loginForm").submit(function(event){
event.preventDefault();
var email = $("#email").val();
var password = $("#password").val();
var submit = $("#submit").val();
$("#err").load("config/config.index.php",{
email: email,
password: password,
submit:submit
});
});
});
config.index.php
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
$errEmptyAll = false;
$errEmptyEmail = false;
$errEmptyPassword = false;
$errEmail = false;
if(empty($email) && empty($password)){
echo 'Please enter an email and password.';
$errEmptyAll = true;
} else if(empty($email)){
echo 'Please enter an email.';
$errEmptyEmail = true;
} else if(empty($password)){
echo 'Please enter a password.';
$errEmptyPassword = true;
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo 'Please enter a valid email.';
$errEmail = true;
}
}
?>
<script>
var errEmptyAll = "<?php echo $errEmptyAll; ?>";
var errEmptyEmail = "<?php echo $errEmptyEmail; ?>";
var errEmptyPassword = "<?php echo $errEmptyPassword; ?>";
var errEmail = "<?php echo $errEmail; ?>";
if(errEmptyAll == true){
$("#email, #password").addClass("inputErr");
}
if(errEmptyEmail == true){
$("#email").addClass("inputErr");
}
if(errEmptyPassword == true){
$("#password").addClass("inputErr");
}
if(errEmail == true){
$("#email").addClass("inputErr");
}
</script>
The config PHP file should not have any JS at all.
Don't use .load(). Use $.ajax to send POST data and listen for server responses.
Build a json_encode response on PHP which will be returned to the browser via AJAX. Read the response data (from PHP) in JavaScript jQuery via the :success property or in the .done() method of $.ajax
index.html
<form id="loginForm" method="post" action="config/config.index.php">
<input type="text" name="email" placeholder="Email" />
<input type="password" name="password" placeholder="Password" />
<button type="submit" name="submit">Log in</button>
</form>
<p id="err"></p>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script srrc="index.js"></script>
index.js
jQuery(($) => { // DOM ready and $ alias in scope
const $err = $("#err");
$("#loginForm").on("submit", function (ev) {
ev.preventDefault(); // prevent browser submit
$(this).find(`[name]`).removeClass("inputErr");
$.ajax({
type: "POST",
dataType: "JSON",
url: this.action, // from form action value
data: $(this).serialize(),
}).done((res) => {
// res is the JSON Response from PHP
console.log(res); // Do with this whatever you want. i.e:
if (res.errors.length) {
$err.text(res.errors.join(", "));
res.fields.forEach(field => {
$(`[name="${field}"]`).addClass("inputErr");
});
} else {
// SUCCESS!!!
}
});
});
});
config/config.index.php
<?php
$response = (object)[
"status" => "error",
"errors" => [],
"fields" => [], // IDs of fields with error
];
if (
$_SERVER["REQUEST_METHOD"] === "POST" &&
isset($_POST["email"]) &&
isset($_POST["password"])
) {
$email = $_POST["email"];
$password = $_POST["password"];
$passwordEmpty = empty($password);
$emailEmpty = empty($email);
$emailInvalid = !filter_var($email, FILTER_VALIDATE_EMAIL);
if ($passwordEmpty) :
$response->errors[] = "Invalid Password";
$response->fields[] = "password";
endif;
if ($emailEmpty) :
$response->errors[] = "Empty Email";
$response->fields[] = "email";
elseif ($emailInvalid) :
$response->errors[] = "Invalid Email";
$response->fields[] = "email";
endif;
if (empty($response->errors)) :
$response->status = "success";
endif;
}
echo json_encode($response);
exit;

Login form validation using php and ajax

I have a login form that has two inputs email and password. If a user enters incorrect credentials, I have to show them the error. I have done form validation in PHP, so I need to send data from the form and get a response message without refreshing the page. I'm new to ajax, so I don't know how to do it
login.php
<form action="register.php" method="POST" autocomplete="off">
<h1 class="card-title display-4 mt-4 mb-5 text-center">Login</h1>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Email" name="email" />
<div class="email-status"></div>
</div>
<div class="form-group">
<input type="password" class="form-control" id="password" placeholder="Password" name="password" />
<div class="password-status"></div>
</div>
<p class="card-text text-center">Forgot your password?</p>
<span class="d-flex justify-content-center">
<button type="submit" class="btn btn-primary mb-4 w-50" style="border-radius: 20px;" name="login_btn" id="login_btn">Login</button>
</span>
<div class="success"></div>
</form>
<script>
$(document).ready(function() {
$("#login_btn").click(function() {
var email = $("#email").val();
var password = $("#password").val();
$.ajax({
url: 'register.php',
type: 'post',
data: {
email: email,
password: password
},
success: function(response) {
var emailstatus = "";
var passwordstatus = "";
var success = "";
if (response == 1) {
emailstatus = "required";
$(".email-status").text(emailstatus);
} else if (response == 2) {
emailstatus = "invalid";
$(".email-status").text(emailstatus);
} else if (response == 3) {
emailstatus = "match";
$(".email-status").text(emailstatus);
} else if (response == 4) {
passwordstatus = "required";
$(".password-status").text(passwordstatus);
} else if (response == 5) {
passwordstatus = "match";
$(".password-status").text(passwordstatus);
} else {
success = "sometihg went wrong";
$(".success").text(success);
}
}
});
});
});
</script>
register.php for form validation
if (isset($_POST['login_btn'])) {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$new_password = md5($password);
$result = mysqli_query($conn, "SELECT * FROM users WHERE email = '$email' OR password = '$new_password' LIMIT 1");
$row = mysqli_fetch_assoc($result);
//EMAIL
if (empty($email)) {
$email_status = "Email is required";
echo 1;
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_status = "Enter valid Email ID";
echo 2;
} elseif ($row['email'] != $email) {
$email_status = "Email doesn't exist";
echo 3;
}
//PASSWORD
elseif (empty($password)) {
$password_status = "Password is required";
echo 4;
} elseif ($row['password'] != $new_password) {
$password_status = "Password doesn't match";
echo 5;
} else {
$query = "SELECT * FROM users WHERE email = '$email' AND password = '$new_password'";
$results = mysqli_query($conn, $query);
if (mysqli_num_rows($results) == 1) {
$rows = mysqli_fetch_array($results);
$_SESSION['username'] = $rows['username'];
$_SESSION['success'] = "You are now logged in";
if (isset($_SESSION['login_redirect'])) {
header("Location: " . $_SESSION["login_redirect"]);
unset($_SESSION["login_redirect"]);
} else if (isset($_SESSION['url'])) {
$url = $_SESSION['url'];
header("Location: $url");
} else {
header("Location: homepage.php");
}
exit;
} else {
$success = "Something went wrong";
echo 6;
}
}
}
If I run the above code, the page gets refresh and I'm not getting any response or validation messages
You have to prevent auto form submit. add an Id or a class to your form element and add this code
Inside of document ready
$("#form-id").submit(function(e){
e.preventDefault();
});
And in form element add an Id
<form action="register.php" id='form-id' method="POST" autocomplete="off">
Replace your data object of ajax as follows and your current code will work:
data: {
email: email,
password: password,
login_btn: true
}
You are checking isset of login_btn value which was not pass through the ajax.

How can i add recaptcha properly to my html form?

I have an AJAX HTML form with validation fields. So my problem is that i'm stuck. I want to embed a recaptcha in my form. I want to produce the following result. If the user completes the recaptcha then the form will be sended. Now if i complete the form and the recaptcha correctly the form is not sended.
HTML
function sendContact() {
var valid;
valid = validateContact();
if(valid) {
jQuery.ajax({
url: "contact_mail.php",
data:'userName='+$("#userName").val()+'&userEmail='+$("#userEmail").val()+'&subject='+$("#subject").val()+'&content='+$(content).val(),
type: "POST",
success:function(data){
$("#mail-status").html(data);
},
error:function (){}
});
}
}
function validateContact() {
var valid = true;
$(".demoInputBox").css('background-color','');
$(".info").html('');
if(!$("#userName").val()) {
$("#userName-info").html("<span style='color: #F00423';>Απαιτούμενο πεδίο</span>");
$("#userName").css('background-color','#3E3E3E');
valid = false;
}
if(!$("#userEmail").val()) {
$("#userEmail-info").html("<span style='color: #F00423';>Απαιτούμενο πεδίο</span>");
$("#userEmail").css('background-color','#3E3E3E');
valid = false;
}
if(!$("#userEmail").val().match(/^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/)) {
$("#userEmail-info").html("<span style='color: #F00423';>Απαιτούμενο πεδίο</span>");
$("#userEmail").css('background-color','#3E3E3E');
valid = false;
}
if(!$("#subject").val()) {
$("#subject-info").html("<span style='color: #F00423';>Απαιτούμενο πεδίο</span>");
$("#subject").css('background-color','#3E3E3E');
valid = false;
}
if(!$("#content").val()) {
$("#content-info").html("<span style='color: #F00423';>Απαιτούμενο πεδίο</span>");
$("#content").css('background-color','#3E3E3E');
valid = false;
}
return valid;
}
</script>
<div id="frmContact">
<div id="mail-status"></div>
<div>
<span id="userName-info" class="info"></span><br/>
<input type="text" name="userName" id="userName" class="form-control form-dark demoInputBox" placeholder="Όνομα">
</div>
<div>
<span id="userEmail-info" class="info"></span><br/>
<input type="text" name="userEmail" id="userEmail" class="form-control form-dark demoInputBox" placeholder="Email">
</div>
<div>
<span id="subject-info" class="info"></span><br/>
<input type="number" name="subject" id="subject" class="form-control form-dark demoInputBox" placeholder="Τηλέφωνο">
</div>
<div>
<span id="content-info" class="info"></span><br/>
<textarea name="content" id="content" class="form-control form-dark demoInputBox" cols="60" rows="6" placeholder="Μήνυμα"></textarea>
</div>
<div>
<div class="g-recaptcha" data-theme="dark" data-sitekey="6LcoXZ0UAAAAAMdgKIlchJvizDWic5S7nwr5XD3g"></div>
<button name="submit" class="btn btn-border border-white btnAction" onClick="sendContact();">Αποστολη</button>
</div>
</div>
PHP
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// access
$secretKey = '6LcoXZ0UAAAAAF3U4SSfiKPZ7NWyuATN7NFh8fKE';
$captcha = $_POST['g-recaptcha-response'];
if(!$captcha){
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
exit;
}
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
} else {
$to = "vp#digital-media.gr";
$msg = "name:\t$_REQUEST[userName]\n";
$msg .= "email:\t$_REQUEST[userEmail]\n";
$msg .= "tel:\t$_REQUEST[subject]\n";
$msg .= "message:\t$_REQUEST[content]\n";
$success = mail($to, "Mail from our site", $msg, "Content-type: text/plain; charset=UTF-8");
if($success) {
print "<p class='success'>Ευχαριστούμε, το μήνυμα σας έχει σταλθεί. Θα σας απαντήσουμε το συντομότερο.</p>";
} else {
print "<p class='Error'>Υπήρξε ένα σφάλμα, δοκιμάστε αργότερα! </p>";
}
}
?>

How to stay on same page after login

I am building an event registration system which displays event registration list if the user is logged in without page refresh using Ajax. However, when I try to login I get undefined index name on line echo "Hello ".$_SESSION["name"]."<br/>"; in index.php. My code is:-
index.php:-
<?php
ob_start();
session_start();
require_once('dbconnect.php');
require_once('function.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Registration</title>
<link href="style.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="crossorigin="anonymous"></script>
<script src="script.js"></script>
</head>
<body>
<div id="wrapper">
<!--Login div-->
<div id="logincontainer">
<form id="loginform" method="post">
<h3>Login</h3>
<div class="display-error" style="display: none;"></div>
<input type="email" name="lemail" placeholder="Enter email address" required>
<input type="password" name="lpassword" placeholder="Enter password" required>
<input type="submit" value="Sign In">
<p>Forgot Password</p>
<p id="bottom">Don't have an account yet? Sign up</p>
</form>
</div>
<div id="signupcontainer">
<form id="registerform" method="post">
<h3>Register</h3>
<div class="display-error" style="display: none;"></div>
<input type="text" name="rname" placeholder="Full Name" required>
<input type="email" name="remail" placeholder="Enter valid email" required>
<input type="password" name="rpassword" placeholder="Password" required>
<input type="text" name="rmobile" maxlength="10" pattern="[0-9]{10}" placeholder="Mobile" required>
<input type="submit" value="Create Account">
<p id="bottom">Already have an account? Sign In</p>
</form>
</div>
<!--Testing refresh portion-->
<div id="after-login" style="display: none;">
<?php
echo "Hello ".$_SESSION["name"]."<br/>";
echo '<span class="glyphicon glyphicon-logout"></span>Sign Out<br/>';
?>
<form id="events" method="post">
Code Ardor<input type="checkbox" name="coding[]" value="ardor">
Designophy<input type="checkbox" name="coding[]" value="design"><br>
<input type="submit" value="Submit" name="submit-btn">
</form>
</div>
<!--Testing portion ends-->
</div>
<script>
$(document).ready(function(){
$("#loginform").submit(function(){
var data = $("#loginform").serialize();
checkRecords(data);
return false;
});
function checkRecords(data){
$.ajax({
url : 'loginprocess.php',
data : data,
type : 'POST',
dataType : 'json',
success: function(data){
if(data.code == 200){
//alert('You have successfully logged in');
//window.location='dashboard.php';
$("#logincontainer").hide();
$("#after-login").show();
}
else{
$(".display-error").html("<ul>"+data.msg+"</ul");
$(".display-error").css("display","block");
}
},
error: function(){
alert("Email/Password is Incorrect");
}
});
}
});
</script>
<!--Signup Ajax-->
<script>
$(document).ready(function(){
$("#registerform").submit(function(){
var data = $("#registerform").serialize();
signupRecords(data);
return false;
});
function signupRecords(data){
$.ajax({
url : 'signupprocess.php',
data : data,
type : 'POST',
dataType : 'json',
success: function(data){
if(data.code == 200){
alert('You have successfully Signed Up \n Please Login now.');
setTimeout(function(){
location.reload();
},500);
}
else{
$(".display-error").html("<ul>"+data.msg+"</ul");
$(".display-error").css("display","block");
}
},
error: function(jqXHR,exception){
console.log(jqXHR);
}
});
}
});
</script>
</body>
loginprocess.php
<?php
ob_start();
session_start();
require_once('dbconnect.php');
require_once('function.php');
$errorMsg = "";
$email = trim($_POST["lemail"]);
$password = trim($_POST["lpassword"]);
if(empty($email)){
$errorMsg .= "<li>Email is required</li>";
}
else{
$email = filterEmail($email);
if($email == FALSE){
$errorMsg .= "<li>Invalid Email Format</li>";
}
}
if(empty($password)){
$errorMsg .= "<li>Password Required.</li>";
}
else{
$password = $password;
}
if(empty($errorMsg)){
$query = $db->prepare("SELECT password from users WHERE email = ?");
$query->execute(array($email));
$pwd = $query->fetchColumn();
if(password_verify($password, $pwd)){
$_SESSION['email'] = $email;
//Testing piece
$qry = $db->prepare("SELECT name from users WHERE email = ?");
$qry->execute(array($email));
$nme = $qry->fetchColumn();
$_SESSION['name']=$nme;
//Testing code ends
echo json_encode(['code'=>200, 'email'=>$_SESSION['email']]);
exit;
}
else{
json_encode(['code'=>400, 'msg'=>'Invalid Email/Password']);
exit;
}
}
else{
echo json_encode(['code'=>404, 'msg'=>$errorMsg]);
}
?>
As far as I can see the problem is that after login call you DO NOT reload the #after-login container contents - you only show it.
if(data.code == 200){
//alert('You have successfully logged in');
//window.location='dashboard.php';
$("#logincontainer").hide();
$("#after-login").show();
}
In the other words the #after-login contents only load on the first page load (before login) and then are not updated by your ajax call (only then you would have access to $_SESSION["name"]).
IMHO proper solution would be to return the $_SESSION["name"] value in the loginprocess.php response and update it in the #after-login container before showing it (eg. use an empty span where the name should appear which you'll fill out on login).
//Something like
if(data.code == 200){
//alert('You have successfully logged in');
//window.location='dashboard.php';
$("span#name_placeholder").text(data.name) //return name from loginprocess.php
$("#logincontainer").hide();
$("#after-login").show();
}
The best solution would to be to create a html element like this for the
<div id="after-login" style="display: none;">
<h5 id="Username"></h5>
<?php
echo '<span class="glyphicon glyphicon-logout"></span>Sign Out<br/>';
?>
<form id="events" method="post">
Code Ardor<input type="checkbox" name="coding[]" value="ardor">
Designophy<input type="checkbox" name="coding[]" value="design"><br>
<input type="submit" value="Submit" name="submit-btn">
</form>
</div>
then after this include the username in the json like this
$qry = $db->prepare("SELECT name from users WHERE email = ?");
$qry->execute(array($email));
$nme = $qry->fetchColumn();
//$_SESSION['name']=$nme;
//Testing code ends
echo json_encode(['code'=>200, 'email'=>$_SESSION['email'],'username'=>$nme]);
exit;
on the ajax call you can now access the json response with the username included and feed the span element with the username like this
if(data.code == 200){
//alert('You have successfully logged in');
//window.location='dashboard.php';
$("#username").test(data.username);
$("#logincontainer").hide();
$("#after-login").show();
}

AJAX page not meeting success criteria...Error in JSON return type....Always showing "There is an error" no matter what

**Hi guys. I created an AJAX page that validates a form and displays errors.But the problem is no matter what it always displays there is an error **
Contact form:
<form id="contact-form" method="post" action="">
<fieldset>
<label for="name" class="fullname">
<span>Full name:</span>
<input type="text" name="fullname" id="fullname">
</label>
<label for="email" class="email">
<span>Email:</span>
<input type="email" name="email" id="email">
</label>
<label for="name1" class="message">
<span>Message:</span>
<textarea name="name1" id="name1"></textarea>
</label>
<div class="btns">
<a class="button" onClick="document.getElementById('contact-form').reset()">Clear</a>
<a class="button" name="submit" id="submit">Send</a>
</div>
</form>
The AJAX program that I wrote is
<script>
$(document).ready(function(){
$('#submit').click(function() {
$('#contact-form').hide(0);
$('#message').hide(0);
$.ajax({
type : 'POST',
url : 'post.php',
dataType : 'json',
data: {
email : $('#email').val(),
name1 : $('#name1').val(),
name : $('#fullname').val()
},
success : function(data){
$('#waiting').hide(500);
$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
$('#contact-form').show(500);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$('#waiting').hide(500);
$('#message').removeClass().addClass('error')
.text('There was an error.').show(500);
$('#contact-form').show(500);
}
});
return false;
});
});
</script>
And Lastly the PHP Code for Validation is
<?php
$return['error'] = false;
while (true) {
if (empty($_POST['email'])) {
$return['error'] = true;
$return['msg'] = 'You did not enter you email.';
break;
}
if (empty($_POST['name'])) {
$return['error'] = true;
$return['msg'] = 'You did not enter you name.';
break;
}
if (empty($_POST['name1'])) {
$return['error'] = true;
$return['msg'] = 'You did not enter you message.';
break;
}
break;
}
if (!$return['error'])
$return['msg'] = 'You\'ve entered: ' . $_POST['email'] . ' as email, ' . $_POST['name'] . ' as name and ' . $_POST['email'] . ' as url.';
echo json_encode($return);
?>
It would be great help if extra validators for email check and length check are added.Thanks a LOT in advance.
Change your input type text or write valide email
<input ng-model="t.unsubscribeEmail" type="text" class="textboxfields" placeholder="Enter email address">
or write valide email in
<input ng-model="t.unsubscribeEmail" type="email" class="textboxfields" placeholder="Enter email address">
use this link

Categories