PHP Form Validation: Form will submit regardless if it passes validation or not [duplicate]












1
















This question already has an answer here:




  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers



  • PHP form validation not working, allowing invalid submissions to be sent



So I have asked a similar question but in the comments, I was told a possible answer however it didn't work so I'm posting another one. The situation is slightly different so I didn't know whether to edit and update the other one or make a new one.



Anyway, I have a form and a PHP script that is supposed to validate the form data when the user submits and for now(testing purposes) if it does not pass the validation an array with strings should print.



Berfore I go on here is the html:



<form method="post" action="mail3.php" class="col-12" id="form-book">
<div class="row">
<div class=" form-group col-12">
<p>Fill out the form below to tell me about your problem. <strong>Any problems to do with technology, all the solutions.</strong> Just tell me what you can, however the more info you give the better.</p>
</div>
<div class="form-group col-6">
<label></label>
<input id="name" name="name" placeholder="Name" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<label></label>
<input id="phone" name="phone" placeholder="Phone#" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-12">
<label></label>
<input id="email" name="email" placeholder="Email (Optional)" type="text" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<input data-provide="datepicker" id="date" name="date" placeholder="Pick a date" required="required" class="form-control here bottom">
</div>
<div class="form-group col-6">
<input type="text" id="time" name="time" placeholder="Choose the best time" required="required" class="form-control here bottom timepicker">
</div>
<div class="form-group col-12">
<label></label>
<textarea id="message" name="message" cols="40" rows="5" class="form-control" required="required" aria-describedby="messageHelpBlock"></textarea>
<span id="messageHelpBlock" class="form-text text-muted">Tell me a little about whats going on or what you need help with.</span>
</div>
<div class="form-group col-12">
<button name="submit" type="submit" class="btn btn-primary">Send your message</button>
</div>
</div>
<!--row-->
</form>


PHP:



                <?php
date_default_timezone_set("Pacific/Honolulu"); //set the DateTimeZone

function test_input($data) { //test input func that checks data
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$date = $_POST['date'];
$time = $_POST['time'];
$message = $_POST['message'];
$subject = "Appointment Booked";
$email = filter_var($email, FILTER_SANITIZE_EMAIL); //clean email
$mailTo = "itguy@johnpuaoi.com";
$dateTested = test_input($date);
$timeTested = test_input($time);

$errors = ; //set errors arrray

//funcs will check each input and if an error is detected it will add a string to errors array
//if no errors are found the input is then passed into xTested variable
function validateName($input) {
if (empty($input)) { //check if empty
return $errors = "Your name is required."; //if empty add string to errors array
} elseif (is_int($input)) { //check if input is an interger
return $errors = "That is not a valid name."; //if is interger add string to errors array
} else {
return $nameTested = test_input($input); //return tested input variable
}
}
function validatePhone($input) {
if (empty($input)) { //check if empty
return $errors = "Your phone number is required."; //add string to array if empty
} elseif (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $input)) { //check if input does not match
return $errors = "That is not a valid name."; //add string to array if no match
} else {
return $phoneTested = test_input($input); //return tested input variable
}
}
function validateEmail($input) {
if (empty($input)) { //check if empty
return $errors = "Your email is required.";//add string to array if empty
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $errors = "That is not a valid email.";
} else {
return $emailTested = test_input($input); //return tested input variable
}
}
function validateMessage($input) {
if (empty($input)) { //check if empty
return $errors = "Your message can't be empty.";//add string to array if empty
} else {
return $messageTested = test_input($input); //return tested input variable
}
}
validateName($name); //call validate funcs
validatePhone($phone);
validateEmail($email);
validateMessage($message);

$headers = "From: ".$emailTested;
$txt = "An appointment was booked by ".$nameTested.".nn".$dateTested." @".$timeTested.".nn".$messageTested;

if ($errors == null) { //if errors array is empty
mail($mailTo, $subject, $txt, $headers); //mail data
header("Location: index.php?mailsend"); //redirect to home
} else {
print $errors; //print errors to test if validate funcs work
}
}
?>


Now I have created validate functions for a set data type - name, email, phone and message. It checks the input and if an error occurs then a string is added to the errors array. If no error is found then the input is passed to a variable to tells php it has been tested for errors.



IMPORTANT In the last question I asked, in the comments someone pointed out that I did not have anything stopping the mail func even if the data did not pass validation. So to fix that I included an if statement at the bottom that checks if the errors array is empty. If it is then the mail func is called, if it isn't then for testing purposes the errors array is printed.



I test the script by purposely entering invalid data but the form submits anyway. What is allowing the script to still mail the form data?



Now if you could not tell already, I am new to php so forgive me if I its something simple. I apologize in advance also if I should have just edited the first question.










share|improve this question















marked as duplicate by Patrick Q, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 20:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You aren't assigning the return value of the validation functions to anything.

    – Patrick Q
    Nov 13 '18 at 20:05











  • The scope of the $errors array means it isn't visible to your if statement.

    – Dave
    Nov 13 '18 at 20:07











  • Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

    – johncodes808
    Nov 13 '18 at 20:09













  • @Dave how then do I make $errors avaliable to it

    – johncodes808
    Nov 13 '18 at 20:17











  • You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

    – MichaelvE
    Nov 13 '18 at 20:20


















1
















This question already has an answer here:




  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers



  • PHP form validation not working, allowing invalid submissions to be sent



So I have asked a similar question but in the comments, I was told a possible answer however it didn't work so I'm posting another one. The situation is slightly different so I didn't know whether to edit and update the other one or make a new one.



Anyway, I have a form and a PHP script that is supposed to validate the form data when the user submits and for now(testing purposes) if it does not pass the validation an array with strings should print.



Berfore I go on here is the html:



<form method="post" action="mail3.php" class="col-12" id="form-book">
<div class="row">
<div class=" form-group col-12">
<p>Fill out the form below to tell me about your problem. <strong>Any problems to do with technology, all the solutions.</strong> Just tell me what you can, however the more info you give the better.</p>
</div>
<div class="form-group col-6">
<label></label>
<input id="name" name="name" placeholder="Name" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<label></label>
<input id="phone" name="phone" placeholder="Phone#" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-12">
<label></label>
<input id="email" name="email" placeholder="Email (Optional)" type="text" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<input data-provide="datepicker" id="date" name="date" placeholder="Pick a date" required="required" class="form-control here bottom">
</div>
<div class="form-group col-6">
<input type="text" id="time" name="time" placeholder="Choose the best time" required="required" class="form-control here bottom timepicker">
</div>
<div class="form-group col-12">
<label></label>
<textarea id="message" name="message" cols="40" rows="5" class="form-control" required="required" aria-describedby="messageHelpBlock"></textarea>
<span id="messageHelpBlock" class="form-text text-muted">Tell me a little about whats going on or what you need help with.</span>
</div>
<div class="form-group col-12">
<button name="submit" type="submit" class="btn btn-primary">Send your message</button>
</div>
</div>
<!--row-->
</form>


PHP:



                <?php
date_default_timezone_set("Pacific/Honolulu"); //set the DateTimeZone

function test_input($data) { //test input func that checks data
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$date = $_POST['date'];
$time = $_POST['time'];
$message = $_POST['message'];
$subject = "Appointment Booked";
$email = filter_var($email, FILTER_SANITIZE_EMAIL); //clean email
$mailTo = "itguy@johnpuaoi.com";
$dateTested = test_input($date);
$timeTested = test_input($time);

$errors = ; //set errors arrray

//funcs will check each input and if an error is detected it will add a string to errors array
//if no errors are found the input is then passed into xTested variable
function validateName($input) {
if (empty($input)) { //check if empty
return $errors = "Your name is required."; //if empty add string to errors array
} elseif (is_int($input)) { //check if input is an interger
return $errors = "That is not a valid name."; //if is interger add string to errors array
} else {
return $nameTested = test_input($input); //return tested input variable
}
}
function validatePhone($input) {
if (empty($input)) { //check if empty
return $errors = "Your phone number is required."; //add string to array if empty
} elseif (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $input)) { //check if input does not match
return $errors = "That is not a valid name."; //add string to array if no match
} else {
return $phoneTested = test_input($input); //return tested input variable
}
}
function validateEmail($input) {
if (empty($input)) { //check if empty
return $errors = "Your email is required.";//add string to array if empty
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $errors = "That is not a valid email.";
} else {
return $emailTested = test_input($input); //return tested input variable
}
}
function validateMessage($input) {
if (empty($input)) { //check if empty
return $errors = "Your message can't be empty.";//add string to array if empty
} else {
return $messageTested = test_input($input); //return tested input variable
}
}
validateName($name); //call validate funcs
validatePhone($phone);
validateEmail($email);
validateMessage($message);

$headers = "From: ".$emailTested;
$txt = "An appointment was booked by ".$nameTested.".nn".$dateTested." @".$timeTested.".nn".$messageTested;

if ($errors == null) { //if errors array is empty
mail($mailTo, $subject, $txt, $headers); //mail data
header("Location: index.php?mailsend"); //redirect to home
} else {
print $errors; //print errors to test if validate funcs work
}
}
?>


Now I have created validate functions for a set data type - name, email, phone and message. It checks the input and if an error occurs then a string is added to the errors array. If no error is found then the input is passed to a variable to tells php it has been tested for errors.



IMPORTANT In the last question I asked, in the comments someone pointed out that I did not have anything stopping the mail func even if the data did not pass validation. So to fix that I included an if statement at the bottom that checks if the errors array is empty. If it is then the mail func is called, if it isn't then for testing purposes the errors array is printed.



I test the script by purposely entering invalid data but the form submits anyway. What is allowing the script to still mail the form data?



Now if you could not tell already, I am new to php so forgive me if I its something simple. I apologize in advance also if I should have just edited the first question.










share|improve this question















marked as duplicate by Patrick Q, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 20:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You aren't assigning the return value of the validation functions to anything.

    – Patrick Q
    Nov 13 '18 at 20:05











  • The scope of the $errors array means it isn't visible to your if statement.

    – Dave
    Nov 13 '18 at 20:07











  • Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

    – johncodes808
    Nov 13 '18 at 20:09













  • @Dave how then do I make $errors avaliable to it

    – johncodes808
    Nov 13 '18 at 20:17











  • You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

    – MichaelvE
    Nov 13 '18 at 20:20
















1












1








1









This question already has an answer here:




  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers



  • PHP form validation not working, allowing invalid submissions to be sent



So I have asked a similar question but in the comments, I was told a possible answer however it didn't work so I'm posting another one. The situation is slightly different so I didn't know whether to edit and update the other one or make a new one.



Anyway, I have a form and a PHP script that is supposed to validate the form data when the user submits and for now(testing purposes) if it does not pass the validation an array with strings should print.



Berfore I go on here is the html:



<form method="post" action="mail3.php" class="col-12" id="form-book">
<div class="row">
<div class=" form-group col-12">
<p>Fill out the form below to tell me about your problem. <strong>Any problems to do with technology, all the solutions.</strong> Just tell me what you can, however the more info you give the better.</p>
</div>
<div class="form-group col-6">
<label></label>
<input id="name" name="name" placeholder="Name" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<label></label>
<input id="phone" name="phone" placeholder="Phone#" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-12">
<label></label>
<input id="email" name="email" placeholder="Email (Optional)" type="text" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<input data-provide="datepicker" id="date" name="date" placeholder="Pick a date" required="required" class="form-control here bottom">
</div>
<div class="form-group col-6">
<input type="text" id="time" name="time" placeholder="Choose the best time" required="required" class="form-control here bottom timepicker">
</div>
<div class="form-group col-12">
<label></label>
<textarea id="message" name="message" cols="40" rows="5" class="form-control" required="required" aria-describedby="messageHelpBlock"></textarea>
<span id="messageHelpBlock" class="form-text text-muted">Tell me a little about whats going on or what you need help with.</span>
</div>
<div class="form-group col-12">
<button name="submit" type="submit" class="btn btn-primary">Send your message</button>
</div>
</div>
<!--row-->
</form>


PHP:



                <?php
date_default_timezone_set("Pacific/Honolulu"); //set the DateTimeZone

function test_input($data) { //test input func that checks data
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$date = $_POST['date'];
$time = $_POST['time'];
$message = $_POST['message'];
$subject = "Appointment Booked";
$email = filter_var($email, FILTER_SANITIZE_EMAIL); //clean email
$mailTo = "itguy@johnpuaoi.com";
$dateTested = test_input($date);
$timeTested = test_input($time);

$errors = ; //set errors arrray

//funcs will check each input and if an error is detected it will add a string to errors array
//if no errors are found the input is then passed into xTested variable
function validateName($input) {
if (empty($input)) { //check if empty
return $errors = "Your name is required."; //if empty add string to errors array
} elseif (is_int($input)) { //check if input is an interger
return $errors = "That is not a valid name."; //if is interger add string to errors array
} else {
return $nameTested = test_input($input); //return tested input variable
}
}
function validatePhone($input) {
if (empty($input)) { //check if empty
return $errors = "Your phone number is required."; //add string to array if empty
} elseif (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $input)) { //check if input does not match
return $errors = "That is not a valid name."; //add string to array if no match
} else {
return $phoneTested = test_input($input); //return tested input variable
}
}
function validateEmail($input) {
if (empty($input)) { //check if empty
return $errors = "Your email is required.";//add string to array if empty
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $errors = "That is not a valid email.";
} else {
return $emailTested = test_input($input); //return tested input variable
}
}
function validateMessage($input) {
if (empty($input)) { //check if empty
return $errors = "Your message can't be empty.";//add string to array if empty
} else {
return $messageTested = test_input($input); //return tested input variable
}
}
validateName($name); //call validate funcs
validatePhone($phone);
validateEmail($email);
validateMessage($message);

$headers = "From: ".$emailTested;
$txt = "An appointment was booked by ".$nameTested.".nn".$dateTested." @".$timeTested.".nn".$messageTested;

if ($errors == null) { //if errors array is empty
mail($mailTo, $subject, $txt, $headers); //mail data
header("Location: index.php?mailsend"); //redirect to home
} else {
print $errors; //print errors to test if validate funcs work
}
}
?>


Now I have created validate functions for a set data type - name, email, phone and message. It checks the input and if an error occurs then a string is added to the errors array. If no error is found then the input is passed to a variable to tells php it has been tested for errors.



IMPORTANT In the last question I asked, in the comments someone pointed out that I did not have anything stopping the mail func even if the data did not pass validation. So to fix that I included an if statement at the bottom that checks if the errors array is empty. If it is then the mail func is called, if it isn't then for testing purposes the errors array is printed.



I test the script by purposely entering invalid data but the form submits anyway. What is allowing the script to still mail the form data?



Now if you could not tell already, I am new to php so forgive me if I its something simple. I apologize in advance also if I should have just edited the first question.










share|improve this question

















This question already has an answer here:




  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers



  • PHP form validation not working, allowing invalid submissions to be sent



So I have asked a similar question but in the comments, I was told a possible answer however it didn't work so I'm posting another one. The situation is slightly different so I didn't know whether to edit and update the other one or make a new one.



Anyway, I have a form and a PHP script that is supposed to validate the form data when the user submits and for now(testing purposes) if it does not pass the validation an array with strings should print.



Berfore I go on here is the html:



<form method="post" action="mail3.php" class="col-12" id="form-book">
<div class="row">
<div class=" form-group col-12">
<p>Fill out the form below to tell me about your problem. <strong>Any problems to do with technology, all the solutions.</strong> Just tell me what you can, however the more info you give the better.</p>
</div>
<div class="form-group col-6">
<label></label>
<input id="name" name="name" placeholder="Name" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<label></label>
<input id="phone" name="phone" placeholder="Phone#" type="text" required="required" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-12">
<label></label>
<input id="email" name="email" placeholder="Email (Optional)" type="text" class="form-control here bottom"> <span class="error">
</div>
<div class="form-group col-6">
<input data-provide="datepicker" id="date" name="date" placeholder="Pick a date" required="required" class="form-control here bottom">
</div>
<div class="form-group col-6">
<input type="text" id="time" name="time" placeholder="Choose the best time" required="required" class="form-control here bottom timepicker">
</div>
<div class="form-group col-12">
<label></label>
<textarea id="message" name="message" cols="40" rows="5" class="form-control" required="required" aria-describedby="messageHelpBlock"></textarea>
<span id="messageHelpBlock" class="form-text text-muted">Tell me a little about whats going on or what you need help with.</span>
</div>
<div class="form-group col-12">
<button name="submit" type="submit" class="btn btn-primary">Send your message</button>
</div>
</div>
<!--row-->
</form>


PHP:



                <?php
date_default_timezone_set("Pacific/Honolulu"); //set the DateTimeZone

function test_input($data) { //test input func that checks data
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$date = $_POST['date'];
$time = $_POST['time'];
$message = $_POST['message'];
$subject = "Appointment Booked";
$email = filter_var($email, FILTER_SANITIZE_EMAIL); //clean email
$mailTo = "itguy@johnpuaoi.com";
$dateTested = test_input($date);
$timeTested = test_input($time);

$errors = ; //set errors arrray

//funcs will check each input and if an error is detected it will add a string to errors array
//if no errors are found the input is then passed into xTested variable
function validateName($input) {
if (empty($input)) { //check if empty
return $errors = "Your name is required."; //if empty add string to errors array
} elseif (is_int($input)) { //check if input is an interger
return $errors = "That is not a valid name."; //if is interger add string to errors array
} else {
return $nameTested = test_input($input); //return tested input variable
}
}
function validatePhone($input) {
if (empty($input)) { //check if empty
return $errors = "Your phone number is required."; //add string to array if empty
} elseif (!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $input)) { //check if input does not match
return $errors = "That is not a valid name."; //add string to array if no match
} else {
return $phoneTested = test_input($input); //return tested input variable
}
}
function validateEmail($input) {
if (empty($input)) { //check if empty
return $errors = "Your email is required.";//add string to array if empty
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $errors = "That is not a valid email.";
} else {
return $emailTested = test_input($input); //return tested input variable
}
}
function validateMessage($input) {
if (empty($input)) { //check if empty
return $errors = "Your message can't be empty.";//add string to array if empty
} else {
return $messageTested = test_input($input); //return tested input variable
}
}
validateName($name); //call validate funcs
validatePhone($phone);
validateEmail($email);
validateMessage($message);

$headers = "From: ".$emailTested;
$txt = "An appointment was booked by ".$nameTested.".nn".$dateTested." @".$timeTested.".nn".$messageTested;

if ($errors == null) { //if errors array is empty
mail($mailTo, $subject, $txt, $headers); //mail data
header("Location: index.php?mailsend"); //redirect to home
} else {
print $errors; //print errors to test if validate funcs work
}
}
?>


Now I have created validate functions for a set data type - name, email, phone and message. It checks the input and if an error occurs then a string is added to the errors array. If no error is found then the input is passed to a variable to tells php it has been tested for errors.



IMPORTANT In the last question I asked, in the comments someone pointed out that I did not have anything stopping the mail func even if the data did not pass validation. So to fix that I included an if statement at the bottom that checks if the errors array is empty. If it is then the mail func is called, if it isn't then for testing purposes the errors array is printed.



I test the script by purposely entering invalid data but the form submits anyway. What is allowing the script to still mail the form data?



Now if you could not tell already, I am new to php so forgive me if I its something simple. I apologize in advance also if I should have just edited the first question.





This question already has an answer here:




  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?

    3 answers



  • PHP form validation not working, allowing invalid submissions to be sent







php forms validation if-statement






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 20:07







johncodes808

















asked Nov 13 '18 at 20:00









johncodes808johncodes808

62




62




marked as duplicate by Patrick Q, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 20:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Patrick Q, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 20:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • You aren't assigning the return value of the validation functions to anything.

    – Patrick Q
    Nov 13 '18 at 20:05











  • The scope of the $errors array means it isn't visible to your if statement.

    – Dave
    Nov 13 '18 at 20:07











  • Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

    – johncodes808
    Nov 13 '18 at 20:09













  • @Dave how then do I make $errors avaliable to it

    – johncodes808
    Nov 13 '18 at 20:17











  • You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

    – MichaelvE
    Nov 13 '18 at 20:20





















  • You aren't assigning the return value of the validation functions to anything.

    – Patrick Q
    Nov 13 '18 at 20:05











  • The scope of the $errors array means it isn't visible to your if statement.

    – Dave
    Nov 13 '18 at 20:07











  • Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

    – johncodes808
    Nov 13 '18 at 20:09













  • @Dave how then do I make $errors avaliable to it

    – johncodes808
    Nov 13 '18 at 20:17











  • You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

    – MichaelvE
    Nov 13 '18 at 20:20



















You aren't assigning the return value of the validation functions to anything.

– Patrick Q
Nov 13 '18 at 20:05





You aren't assigning the return value of the validation functions to anything.

– Patrick Q
Nov 13 '18 at 20:05













The scope of the $errors array means it isn't visible to your if statement.

– Dave
Nov 13 '18 at 20:07





The scope of the $errors array means it isn't visible to your if statement.

– Dave
Nov 13 '18 at 20:07













Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

– johncodes808
Nov 13 '18 at 20:09







Isn't that what the "return $nameTested = test_input($input);" does? or should it be "$nameTested = test_input($input); then return $nameTested?

– johncodes808
Nov 13 '18 at 20:09















@Dave how then do I make $errors avaliable to it

– johncodes808
Nov 13 '18 at 20:17





@Dave how then do I make $errors avaliable to it

– johncodes808
Nov 13 '18 at 20:17













You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

– MichaelvE
Nov 13 '18 at 20:20







You can make your $errors array a global variable. Within each of your functions refer to your $errors array as $GLOBALS['errors']

– MichaelvE
Nov 13 '18 at 20:20














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma