Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom php error message fadein

I have written the following code as part of the user signup process for my website. Obviously once the user has filled out their email and clicks submit the form data is sent through this:

<?php

if(isset($_POST['email'])){

$email_from = $_POST['email'];

function died($error) {
    echo $error;
    die();
}

if(!isset($_POST['email'])) {
    died($error);
}

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {

  $error_message .= ' <script type="text/javascript">
  alert("The email address you entered does not appear to be valid");
  window.location = "http://www.domain.com/";
  </script> ' ;
    }

if(strlen($error_message) > 0) {
    died($error_message);
}

etc, etc, etc....

What i would really appreciate some help with is this bit of script:

$error_message .= ' <script type="text/javascript">
  alert("The email address you entered does not appear to be valid");
  window.location = "http://www.domain.com/";
  </script> ' ;
    }

How can create an error message that just fades in (and out on click) on the html page, rather than just being a js alert infront of the blank white php page before redirecting to the html page??

Thank you!


1 Answers

<span class="fadeInMessage" style="display:none;">"The email address you entered does not appear to be valid"</span>

This would start off invisible. Then you would write the following code:

$(function(){
    $('.fadeInMessage').fadeIn();
});
like image 81
Zevi Sternlicht Avatar answered Jul 23 '26 19:07

Zevi Sternlicht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!