Jump to content

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


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...