Jump to content

I would like to know how can I send the form after the validation?


Slater8242

Recommended Posts

This is my validation function

class emailValidation {
    public $emailMessage="";
    function checkemail($emailText) {
        return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $emailText) ) ? FALSE : TRUE;
    }
    
    function columbia($emailText){
        return (!preg_match("/@([\w-])+\.co$/mi", $emailText)) ? FALSE : TRUE;
    }

    function validation(){
        if(isset($_POST['emailSubmit'])){
            if (empty($_POST["emailText"])) {
              $this->emailMessage = "Email is required";
            } else {
              $emailText = $_POST["emailText"];
                if (!$this->checkEmail($emailText)) {
                 $this->emailMessage = "Invalid email format";
                }
                if ($this->columbia($emailText)) {
                    $this->emailMessage = "We do not accept emails from Columbia";
                }
            }
        }
    }

and this is data insert function

require('dbConnection.php');

class subscribers extends dbConnection{

    public function insertSubscribers(){
        if (isset($_POST["emailSubmit"])) {
            $email=$_POST["emailText"];

            $sql = "INSERT INTO subscribers (email) VALUES ('$email');";
            $result = $this->connect()->query($sql);
            header("Location: /success.html");
        }
        
    }
}

I am thinking to put insertSubscribers() into the validation() function

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...