Topic: PHP validation (server side validation)

demzl25 pro asked 5 years ago


Hi, how can i add  PHP validation (server side validation) when form was successfully validated  and then to redirect to specific page? This si PHP from MDB: <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $subject = $_POST['subject']; header('Content-Type: application/json'); if ($name === ''){ print json_encode(array('message' => 'Name cannot be empty', 'code' => 0)); exit(); } if ($email === ''){ print json_encode(array('message' => 'Email cannot be empty', 'code' => 0)); exit(); } else { if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ print json_encode(array('message' => 'Email format invalid.', 'code' => 0)); exit(); } } if ($subject === ''){ print json_encode(array('message' => 'Subject cannot be empty', 'code' => 0)); exit(); } if ($message === ''){ print json_encode(array('message' => 'Message cannot be empty', 'code' => 0)); exit(); } $content="From: $name nEmail: $email nMessage: $message"; $recipient = "youremail@here.com"; $mailheader = "From: $email rn"; mail($recipient, $subject, $content, $mailheader) or die("Error!"); print json_encode(array('message' => 'Email successfully sent!', 'code' => 1)); exit(); ?>

Witold Tkaczyk free answered 5 years ago


Hi demzl25, you can do this in your javascript file, on a response from mail.php if code === 1 or in PHP before any output is given.

demzl25 pro commented 5 years ago

Can you help me with this i dont know much about java script or php?

Dawid Adach pro commented 5 years ago

Simply use window.location = "http://www.yoururl.com"; JS function whenever you want to redirect user.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags