{"id":54,"date":"2019-01-31T12:20:28","date_gmt":"2019-01-31T06:50:28","guid":{"rendered":"https:\/\/www.onlinenote.in\/codeigniter\/?p=54"},"modified":"2019-01-31T12:20:28","modified_gmt":"2019-01-31T06:50:28","slug":"sample-contact-form-with-validation-captcha-notification","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/","title":{"rendered":"Sample Contact Form with validation, Captcha &#038; Notification"},"content":{"rendered":"<p>Contact Controller<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');\r\n\r\nclass Contact extends Public_Controller {\r\n\r\n    \/**\r\n     * Constructor\r\n     *\/\r\n    function __construct()\r\n    {\r\n        parent::__construct();\r\n\r\n        \/\/ load the model file\r\n        $this-&gt;load-&gt;model('contact_model');\r\n        $this-&gt;load-&gt;model('notifications_model');\r\n\r\n        \/\/ load the captcha helper\r\n        $this-&gt;load-&gt;helper('captcha');\r\n    }\r\n\r\n\r\n    \/**************************************************************************************\r\n     * PUBLIC FUNCTIONS\r\n     **************************************************************************************\/\r\n\r\n\r\n    \/**\r\n     * Default\r\n     *\/\r\n    public function index()\r\n    {\r\n        \/\/ validators\r\n        $this-&gt;form_validation-&gt;set_error_delimiters($this-&gt;config-&gt;item('error_delimeter_left'), $this-&gt;config-&gt;item('error_delimeter_right'));\r\n        $this-&gt;form_validation-&gt;set_rules('name', lang('contacts_name'), 'required|trim|max_length[64]');\r\n        $this-&gt;form_validation-&gt;set_rules('email', lang('contacts_email'), 'required|trim|valid_email|min_length[10]|max_length[256]');\r\n        $this-&gt;form_validation-&gt;set_rules('title', lang('common_title'), 'required|trim|max_length[128]');\r\n        $this-&gt;form_validation-&gt;set_rules('message', lang('contacts_message'), 'required|trim|min_length[10]');\r\n        $this-&gt;form_validation-&gt;set_rules('captcha', lang('contacts_captcha'), 'required|trim|callback__check_captcha');\r\n\r\n        if ($this-&gt;form_validation-&gt;run() == TRUE)\r\n        {\r\n            \/\/ attempt to save and send the message\r\n            $post_data = $this-&gt;security-&gt;xss_clean($this-&gt;input-&gt;post());\r\n            $saved_and_sent = $this-&gt;contact_model-&gt;save_and_send_message($post_data, $this-&gt;settings);\r\n\r\n            if ($saved_and_sent)\r\n            {\r\n                $notification   = array(\r\n                    'users_id'  =&gt; 1,\r\n                    'n_type'    =&gt; 'contacts',\r\n                    'n_content' =&gt; 'noti_new_message',\r\n                    'n_url'     =&gt; site_url('admin\/contacts'),\r\n                );\r\n                $this-&gt;notifications_model-&gt;save_notifications($notification);\r\n\r\n                \/\/ redirect to home page\r\n                $this-&gt;session-&gt;set_flashdata('message', sprintf(lang('contacts_send_success'), $this-&gt;input-&gt;post('name', TRUE)));\r\n                redirect(site_url('contact'));\r\n            }\r\n            else\r\n            {\r\n                \/\/ stay on contact page\r\n                $this-&gt;error = sprintf(lang('contacts_error_send_failed'), $this-&gt;input-&gt;post('name', TRUE));\r\n            }\r\n        }\r\n\r\n        \/\/ create captcha image\r\n        $captcha = create_captcha(array(\r\n            'img_path'   =&gt; \".\/captcha\/\",\r\n            'img_url'    =&gt; base_url('\/captcha') . \"\/\",\r\n            'font_path'  =&gt; FCPATH . \"themes\/core\/fonts\/bromine\/Bromine.ttf\",\r\n            'img_width'\t =&gt; 300,\r\n            'img_height' =&gt; 100\r\n        ));\r\n\r\n        $captcha_data = array(\r\n            'captcha_time' =&gt; $captcha['time'],\r\n            'ip_address'   =&gt; $this-&gt;input-&gt;ip_address(),\r\n            'word'\t       =&gt; $captcha['word']\r\n        );\r\n\r\n        \/\/ store captcha image\r\n        $this-&gt;contact_model-&gt;save_captcha($captcha_data);\r\n\r\n        \/\/ setup page header data\r\n        $this\r\n        -&gt;add_js_theme( \"pages\/contact\/index.js\")\r\n        -&gt;set_title( lang('menu_contact') );\r\n\r\n        $data = $this-&gt;includes;\r\n\r\n        \/\/ set content data\r\n        $content_data = array(\r\n            'captcha_image' =&gt; $captcha['image']\r\n        );\r\n\r\n        \/\/ load views\r\n        $data['content'] = $this-&gt;load-&gt;view('contact_form', $content_data, TRUE);\r\n        $this-&gt;load-&gt;view($this-&gt;template, $data);\r\n    }\r\n\r\n\r\n    \/**************************************************************************************\r\n     * PRIVATE VALIDATION CALLBACK FUNCTIONS\r\n     **************************************************************************************\/\r\n\r\n\r\n    \/**\r\n     * Verifies correct CAPTCHA value\r\n     *\r\n     * @param  string $captcha\r\n     * @return string|boolean\r\n     *\/\r\n    function _check_captcha($captcha)\r\n    {\r\n        $verified = $this-&gt;contact_model-&gt;verify_captcha($captcha);\r\n\r\n        if ($verified == FALSE)\r\n        {\r\n            $this-&gt;form_validation-&gt;set_message('_check_captcha', lang('contacts_error_captcha'));\r\n            return FALSE;\r\n        }\r\n        else\r\n        {\r\n            return $captcha;\r\n        }\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>Contact_form.php &#8211; view<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php defined('BASEPATH') OR exit('No direct script access allowed'); ?&gt;\r\n\r\n&lt;!-- Section --&gt;\r\n&lt;section class=\"bg-lgrey\"&gt;  \r\n    &lt;div class=\"container\"&gt;\r\n        &lt;div class=\"row\"&gt;\r\n            &lt;div class=\"col-sm-offset-1 col-sm-4\"&gt;\r\n                &lt;!-- Title --&gt;\r\n                &lt;div class=\"title-container sm text-left\"&gt;\r\n                    &lt;div class=\"title-wrap\"&gt;\r\n                        &lt;h5 class=\"title\"&gt;&lt;?php echo lang('menu_contact') ?&gt;&lt;\/h5&gt;\r\n                        &lt;span class=\"separator line-separator\"&gt;&lt;\/span&gt;\r\n                    &lt;\/div&gt;\r\n                &lt;\/div&gt;&lt;!-- Title --&gt;\r\n                &lt;div class=\"contact-info\"&gt;\r\n                    &lt;div class=\"info-icon bg-dark\"&gt;\r\n                        &lt;i class=\"uni-map2\"&gt;&lt;\/i&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;h5 class=\"title\"&gt;&lt;?php echo lang('contacts_office') ?&gt;&lt;\/h5&gt;\r\n                    &lt;p&gt;&lt;?php echo $this-&gt;settings-&gt;institute_name ?&gt;&lt;\/p&gt;\r\n                    &lt;p&gt;&lt;?php echo $this-&gt;settings-&gt;institute_address ?&gt;&lt;\/p&gt;\r\n                &lt;\/div&gt;&lt;!-- Contact Info --&gt;\r\n                \r\n                &lt;div class=\"contact-info margin-top-30\"&gt;\r\n                    &lt;div class=\"info-icon bg-dark\"&gt;\r\n                        &lt;i class=\"uni-mail\"&gt;&lt;\/i&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;h5 class=\"title\"&gt;&lt;?php echo lang('menu_contact') ?&gt;&lt;\/h5&gt;\r\n                    &lt;p&gt;&lt;a href=\"mailto:&lt;?php echo $this-&gt;settings-&gt;site_email ?&gt;\"&gt;&lt;?php echo $this-&gt;settings-&gt;site_email ?&gt;&lt;\/a&gt;&lt;\/p&gt;\r\n                    &lt;p&gt;&lt;a href=\"tel:&lt;?php echo $this-&gt;settings-&gt;institute_phone ?&gt;\"&gt;&lt;?php echo $this-&gt;settings-&gt;institute_phone ?&gt;&lt;\/a&gt;&lt;\/p&gt;\r\n                &lt;\/div&gt;&lt;!-- Contact Info --&gt;\r\n                \r\n            &lt;\/div&gt;&lt;!-- Column --&gt;\r\n            \r\n            &lt;div class=\"col-sm-6\"&gt;\r\n                &lt;!-- Title --&gt;\r\n                &lt;div class=\"title-container sm text-left\"&gt;\r\n                    &lt;div class=\"title-wrap\"&gt;\r\n                        &lt;h5 class=\"title\"&gt;&lt;?php echo lang('contacts_get_in_touch') ?&gt;&lt;\/h5&gt;\r\n                        &lt;span class=\"separator line-separator\"&gt;&lt;\/span&gt;\r\n                    &lt;\/div&gt;\r\n                &lt;\/div&gt;&lt;!-- Title --&gt;\r\n                &lt;div class=\"contact-info\"&gt;\r\n                    &lt;div class=\"info-icon bg-dark\"&gt;\r\n                        &lt;i class=\"uni-fountain-pen\"&gt;&lt;\/i&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;?php echo form_open('', array('role'=&gt;'form', 'id'=&gt;'form-create')); ?&gt;\r\n                    &lt;div class=\"input-text form-group&lt;?php echo form_error('name') ? ' has-error' : ''; ?&gt;\"&gt;\r\n                        &lt;?php echo form_label(lang('contacts_name'), 'name', array('class'=&gt;'control-label')); ?&gt;\r\n                        &lt;span class=\"required\"&gt;*&lt;\/span&gt;\r\n                        &lt;?php echo form_input(array('name'=&gt;'name', 'value'=&gt;set_value('name'), 'class'=&gt;'form-control input-name')); ?&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;div class=\"input-email form-group &lt;?php echo form_error('email') ? ' has-error' : ''; ?&gt;\"&gt;\r\n                        &lt;?php echo form_label(lang('contacts_email'), 'email', array('class'=&gt;'control-label')); ?&gt;\r\n                        &lt;span class=\"required\"&gt;*&lt;\/span&gt;\r\n                        &lt;?php echo form_input(array('name'=&gt;'email', 'value'=&gt;set_value('email'), 'class'=&gt;'form-control input-email')); ?&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;div class=\"input-text form-group &lt;?php echo form_error('title') ? ' has-error' : ''; ?&gt;\"&gt;\r\n                        &lt;?php echo form_label(lang('common_title'), 'title', array('class'=&gt;'control-label')); ?&gt;\r\n                        &lt;span class=\"required\"&gt;*&lt;\/span&gt;\r\n                        &lt;?php echo form_input(array('name'=&gt;'title', 'value'=&gt;set_value('title'), 'class'=&gt;'form-control input-text ')); ?&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;div class=\"textarea-message form-group &lt;?php echo form_error('message') ? ' has-error' : ''; ?&gt;\"&gt;\r\n                        &lt;?php echo form_label(lang('contacts_message'), 'message', array('class'=&gt;'control-label')); ?&gt;\r\n                        &lt;span class=\"required\"&gt;*&lt;\/span&gt;\r\n                        &lt;?php echo form_textarea(array('name'=&gt;'message', 'value'=&gt;set_value('message'), 'class'=&gt;'form-control textarea-message')); ?&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;div class=\"form-group textarea-message &lt;?php echo form_error('captcha') ? ' has-error' : ''; ?&gt;\"&gt;\r\n                        &lt;?php echo form_label(lang('contacts_captcha'), 'captcha', array('class'=&gt;'control-label')); ?&gt;\r\n                        &lt;br \/&gt;\r\n                        &lt;?php echo $captcha_image; ?&gt;\r\n                        &lt;?php echo form_input(array('name'=&gt;'captcha', 'id'=&gt;'captcha', 'value'=&gt;\"\", 'class'=&gt;'form-control textarea-message')); ?&gt;\r\n                    &lt;\/div&gt;\r\n                    &lt;button type=\"submit\" name=\"submit\" class=\"btn\"&gt;&lt;i class=\"fa fa-send\"&gt;&lt;\/i&gt; &lt;?php echo lang('contacts_send_message') ?&gt;&lt;\/button&gt;\r\n                    &lt;span id=\"submit-loader\"&gt;&lt;\/span&gt;\r\n                    &lt;?php echo form_close(); ?&gt;\r\n                &lt;\/div&gt;&lt;!-- Contact Info --&gt;\r\n            &lt;\/div&gt;&lt;!-- Column --&gt;\r\n        &lt;\/div&gt;&lt;!-- Row --&gt;\r\n    &lt;\/div&gt;&lt;!-- Container --&gt;    \r\n&lt;\/section&gt;&lt;!-- Section --&gt;  \r\n<\/pre>\n<p>Contact_model<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');\r\n\r\n\/**\r\n * Contact Model\r\n *\r\n * This model handles contacts module data\r\n *\r\n\r\n*\/\r\n\r\nclass Contact_model extends CI_Model {\r\n\r\n    \/**\r\n     * @vars\r\n     *\/\r\n    private $_db;\r\n\r\n\r\n    \/**\r\n     * Constructor\r\n     *\/\r\n    function __construct()\r\n    {\r\n        parent::__construct();\r\n\r\n        \/\/ define primary table\r\n        $this-&gt;_db = 'emails';\r\n    }\r\n\r\n\r\n    \/**\r\n     * Save generated CAPTCHA to database\r\n     *\r\n     * @param  array $data\r\n     * @return boolean\r\n     *\/\r\n    public function save_captcha($data = array())\r\n    {\r\n        \/\/ CAPTCHA data required\r\n        if ($data)\r\n        {\r\n            \/\/ insert CAPTCHA\r\n            $query = $this-&gt;db-&gt;insert_string('captcha', $data);\r\n            $this-&gt;db-&gt;query($query);\r\n\r\n            \/\/ return\r\n            return TRUE;\r\n        }\r\n\r\n        return FALSE;\r\n    }\r\n\r\n\r\n    \/**\r\n     * Verify CAPTCHA\r\n     *\r\n     * @param  string $captcha\r\n     * @return boolean\r\n     *\/\r\n    public function verify_captcha($captcha = NULL)\r\n    {\r\n        \/\/ CAPTCHA string required\r\n        if ($captcha)\r\n        {\r\n            \/\/ remove old CAPTCHA\r\n            $expiration = time() - 7200; \/\/ 2-hour limit\r\n            $this-&gt;db-&gt;query(\"DELETE FROM captcha WHERE captcha_time &lt; {$expiration}\");\r\n\r\n            \/\/ build query\r\n            $sql = \"\r\n                SELECT\r\n                    COUNT(*) AS count\r\n                FROM captcha\r\n                WHERE word = \" . $this-&gt;db-&gt;escape($captcha) . \"\r\n                    AND ip_address = '\" . $this-&gt;input-&gt;ip_address() . \"'\r\n                    AND captcha_time &gt; '{$expiration}'\r\n            \";\r\n\r\n            \/\/ execute query\r\n            $query = $this-&gt;db-&gt;query($sql);\r\n\r\n            \/\/ return results\r\n            if ($query-&gt;row()-&gt;count &gt; 0)\r\n            {\r\n                return TRUE;\r\n            }\r\n        }\r\n\r\n        return FALSE;\r\n    }\r\n\r\n\r\n    \/**\r\n     * Save and email contact message\r\n     *\r\n     * @param  array $data\r\n     * @param  array $settings\r\n     * @return boolean\r\n     *\/\r\n    public function save_and_send_message($data=array(), $settings=array())\r\n    {\r\n        \/\/ post data and settings required\r\n        if ($data &amp;&amp; $settings)\r\n        {\r\n            \/\/ build query\r\n            $sql = \"\r\n                INSERT INTO {$this-&gt;_db} (\r\n                    name, email, title, message, created\r\n                ) VALUES (\r\n                    \" . $this-&gt;db-&gt;escape($data['name']) . \",\r\n                    \" . $this-&gt;db-&gt;escape($data['email']) . \",\r\n                    \" . $this-&gt;db-&gt;escape($data['title']) . \",\r\n                    \" . $this-&gt;db-&gt;escape($data['message']) . \",\r\n                    '\" . date('Y-m-d H:i:s') . \"'\r\n                )\r\n            \";\r\n\r\n            \/\/ execute query\r\n            $this-&gt;db-&gt;query($sql);\r\n\r\n            if ($id = $this-&gt;db-&gt;insert_id() &amp;&amp; $_SERVER['HTTP_HOST'] !== 'localhost')\r\n            {\r\n                try\r\n                {\r\n                    \/\/ send email\r\n                    $this-&gt;email-&gt;from($data['email'], $data['name']);\r\n                    $this-&gt;email-&gt;to($settings-&gt;site_email);\r\n                    $this-&gt;email-&gt;subject($data['title']);\r\n                    $this-&gt;email-&gt;message($data['message']);\r\n                    $send_mail = @$this-&gt;email-&gt;send();\r\n                    #echo $this-&gt;email-&gt;print_debugger();\r\n\r\n                    if ($send_mail)\r\n                    {\r\n                        return TRUE;\r\n                    }\r\n                    else\r\n                    {\r\n                        \/\/ send mail failed - remove message from database\r\n                        $this-&gt;db-&gt;query(\"DELETE FROM {$this-&gt;_db} WHERE id = {$id}\");\r\n                    }\r\n                }\r\n                catch (Exception $e)\r\n                {\r\n                    \/\/ send mail failed - remove message from database\r\n                    $this-&gt;db-&gt;query(\"DELETE FROM {$this-&gt;_db} WHERE id = {$id}\");\r\n                }\r\n            }\r\n            else\r\n            {\r\n                return TRUE;\r\n            }\r\n        }\r\n\r\n        return FALSE;\r\n    }\r\n\r\n\r\n    \/**\r\n     * Get list of non-deleted users\r\n     *\r\n     * @param  int $limit\r\n     * @param  int $offset\r\n     * @param  array $filters\r\n     * @param  string $sort\r\n     * @param  string $dir\r\n     * @return array|boolean\r\n     *\/\r\n    function get_all($limit = 0, $offset = 0, $filters = array(), $sort = 'created', $dir = 'DESC')\r\n    {\r\n        \/\/ start building query\r\n        $sql = \"\r\n            SELECT SQL_CALC_FOUND_ROWS *\r\n            FROM {$this-&gt;_db}\r\n            WHERE 1 = 1\r\n        \";\r\n\r\n        \/\/ apply filters\r\n        if ( ! empty($filters))\r\n        {\r\n            foreach ($filters as $key=&gt;$value)\r\n            {\r\n                $value = $this-&gt;db-&gt;escape('%' . $value . '%');\r\n                $sql .= \" AND {$key} LIKE {$value}\";\r\n            }\r\n        }\r\n\r\n        \/\/ continue building query\r\n        $sql .= \" ORDER BY {$sort} {$dir}\";\r\n\r\n        \/\/ add limit and offset\r\n        if ($limit)\r\n        {\r\n            $sql .= \" LIMIT {$offset}, {$limit}\";\r\n        }\r\n\r\n        \/\/ execute query\r\n        $query = $this-&gt;db-&gt;query($sql);\r\n\r\n        \/\/ define results\r\n        if ($query-&gt;num_rows() &gt; 0)\r\n        {\r\n            $results['results'] = $query-&gt;result_array();\r\n        }\r\n        else\r\n        {\r\n            $results['results'] = NULL;\r\n        }\r\n\r\n        \/\/ get total count\r\n        $sql = \"SELECT FOUND_ROWS() AS total\";\r\n        $query = $this-&gt;db-&gt;query($sql);\r\n        $results['total'] = $query-&gt;row()-&gt;total;\r\n\r\n        \/\/ return results\r\n        return $results;\r\n    }\r\n\r\n\r\n    \/**\r\n     * Set email message as read\r\n     *\r\n     * @param  int $id\r\n     * @param  int $read_by\r\n     * @return boolean\r\n     *\/\r\n    public function read($id = NULL, $read_by = NULL)\r\n    {\r\n        \/\/ data required\r\n        if ($id and $read_by)\r\n        {\r\n            \/\/ build query string\r\n            $sql = \"\r\n                UPDATE {$this-&gt;_db}\r\n                SET `read` = '\" . date('Y-m-d H:i:s') . \"',\r\n                    read_by = {$read_by}\r\n                WHERE id = {$id}\r\n            \";\r\n\r\n            \/\/ execute query\r\n            $this-&gt;db-&gt;query($sql);\r\n\r\n           \/\/ return results\r\n            if ($this-&gt;db-&gt;affected_rows())\r\n            {\r\n                return TRUE;\r\n            }\r\n        }\r\n\r\n        return FALSE;\r\n    }\r\n\r\n}\r\n\r\n\/*Contact model ends*\/\r\n<\/pre>\n<p>Captcha Helper<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\/**\r\n * CodeIgniter\r\n *\r\n * An open source application development framework for PHP\r\n *\r\n * This content is released under the MIT License (MIT)\r\n *\r\n * Copyright (c) 2014 - 2018, British Columbia Institute of Technology\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and\/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in\r\n * all copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n * THE SOFTWARE.\r\n *\r\n * @package\tCodeIgniter\r\n * @author\tEllisLab Dev Team\r\n * @copyright\tCopyright (c) 2008 - 2014, EllisLab, Inc. (https:\/\/ellislab.com\/)\r\n * @copyright\tCopyright (c) 2014 - 2018, British Columbia Institute of Technology (http:\/\/bcit.ca\/)\r\n * @license\thttp:\/\/opensource.org\/licenses\/MIT\tMIT License\r\n * @link\thttps:\/\/codeigniter.com\r\n * @since\tVersion 1.0.0\r\n * @filesource\r\n *\/\r\ndefined('BASEPATH') OR exit('No direct script access allowed');\r\n\r\n\/**\r\n * CodeIgniter CAPTCHA Helper\r\n *\r\n * @package\t\tCodeIgniter\r\n * @subpackage\tHelpers\r\n * @category\tHelpers\r\n * @author\t\tEllisLab Dev Team\r\n * @link\t\thttps:\/\/codeigniter.com\/user_guide\/helpers\/captcha_helper.html\r\n *\/\r\n\r\n\/\/ ------------------------------------------------------------------------\r\n\r\nif ( ! function_exists('create_captcha'))\r\n{\r\n\t\/**\r\n\t * Create CAPTCHA\r\n\t *\r\n\t * @param\tarray\t$data\t\tData for the CAPTCHA\r\n\t * @param\tstring\t$img_path\tPath to create the image in (deprecated)\r\n\t * @param\tstring\t$img_url\tURL to the CAPTCHA image folder (deprecated)\r\n\t * @param\tstring\t$font_path\tServer path to font (deprecated)\r\n\t * @return\tstring\r\n\t *\/\r\n\tfunction create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')\r\n\t{\r\n\t\t$defaults = array(\r\n\t\t\t'word'\t\t=&gt; '',\r\n\t\t\t'img_path'\t=&gt; '',\r\n\t\t\t'img_url'\t=&gt; '',\r\n\t\t\t'img_width'\t=&gt; '150',\r\n\t\t\t'img_height'\t=&gt; '30',\r\n\t\t\t'font_path'\t=&gt; '',\r\n\t\t\t'expiration'\t=&gt; 7200,\r\n\t\t\t'word_length'\t=&gt; 8,\r\n\t\t\t'font_size'\t=&gt; 16,\r\n\t\t\t'img_id'\t=&gt; '',\r\n\t\t\t'pool'\t\t=&gt; '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',\r\n\t\t\t'colors'\t=&gt; array(\r\n\t\t\t\t'background'\t=&gt; array(255,255,255),\r\n\t\t\t\t'border'\t=&gt; array(153,102,102),\r\n\t\t\t\t'text'\t\t=&gt; array(204,153,153),\r\n\t\t\t\t'grid'\t\t=&gt; array(255,182,182)\r\n\t\t\t)\r\n\t\t);\r\n\r\n\t\tforeach ($defaults as $key =&gt; $val)\r\n\t\t{\r\n\t\t\tif ( ! is_array($data) &amp;&amp; empty($$key))\r\n\t\t\t{\r\n\t\t\t\t$$key = $val;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$$key = isset($data[$key]) ? $data[$key] : $val;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ($img_path === '' OR $img_url === ''\r\n\t\t\tOR ! is_dir($img_path) OR ! is_really_writable($img_path)\r\n\t\t\tOR ! extension_loaded('gd'))\r\n\t\t{\r\n\t\t\treturn FALSE;\r\n\t\t}\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/ Remove old images\r\n\t\t\/\/ -----------------------------------\r\n\r\n\t\t$now = microtime(TRUE);\r\n\r\n\t\t$current_dir = @opendir($img_path);\r\n\t\twhile ($filename = @readdir($current_dir))\r\n\t\t{\r\n\t\t\tif (in_array(substr($filename, -4), array('.jpg', '.png'))\r\n\t\t\t\t&amp;&amp; (str_replace(array('.jpg', '.png'), '', $filename) + $expiration) &lt; $now)\r\n\t\t\t{\r\n\t\t\t\t@unlink($img_path.$filename);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t@closedir($current_dir);\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/ Do we have a \"word\" yet?\r\n\t\t\/\/ -----------------------------------\r\n\r\n\t\tif (empty($word))\r\n\t\t{\r\n\t\t\t$word = '';\r\n\t\t\t$pool_length = strlen($pool);\r\n\t\t\t$rand_max = $pool_length - 1;\r\n\r\n\t\t\t\/\/ PHP7 or a suitable polyfill\r\n\t\t\tif (function_exists('random_int'))\r\n\t\t\t{\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tfor ($i = 0; $i &lt; $word_length; $i++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$word .= $pool[random_int(0, $rand_max)];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcatch (Exception $e)\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/ This means fallback to the next possible\r\n\t\t\t\t\t\/\/ alternative to random_int()\r\n\t\t\t\t\t$word = '';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (empty($word))\r\n\t\t{\r\n\t\t\t\/\/ Nobody will have a larger character pool than\r\n\t\t\t\/\/ 256 characters, but let's handle it just in case ...\r\n\t\t\t\/\/\r\n\t\t\t\/\/ No, I do not care that the fallback to mt_rand() can\r\n\t\t\t\/\/ handle it; if you trigger this, you're very obviously\r\n\t\t\t\/\/ trying to break it. -- Narf\r\n\t\t\tif ($pool_length &gt; 256)\r\n\t\t\t{\r\n\t\t\t\treturn FALSE;\r\n\t\t\t}\r\n\r\n\t\t\t\/\/ We'll try using the operating system's PRNG first,\r\n\t\t\t\/\/ which we can access through CI_Security::get_random_bytes()\r\n\t\t\t$security = get_instance()-&gt;security;\r\n\r\n\t\t\t\/\/ To avoid numerous get_random_bytes() calls, we'll\r\n\t\t\t\/\/ just try fetching as much bytes as we need at once.\r\n\t\t\tif (($bytes = $security-&gt;get_random_bytes($pool_length)) !== FALSE)\r\n\t\t\t{\r\n\t\t\t\t$byte_index = $word_index = 0;\r\n\t\t\t\twhile ($word_index &lt; $word_length)\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/ Do we have more random data to use?\r\n\t\t\t\t\t\/\/ It could be exhausted by previous iterations\r\n\t\t\t\t\t\/\/ ignoring bytes higher than $rand_max.\r\n\t\t\t\t\tif ($byte_index === $pool_length)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\/\/ No failures should be possible if the\r\n\t\t\t\t\t\t\/\/ first get_random_bytes() call didn't\r\n\t\t\t\t\t\t\/\/ return FALSE, but still ...\r\n\t\t\t\t\t\tfor ($i = 0; $i &lt; 5; $i++)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (($bytes = $security-&gt;get_random_bytes($pool_length)) === FALSE)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t$byte_index = 0;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif ($bytes === FALSE)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\/\/ Sadly, this means fallback to mt_rand()\r\n\t\t\t\t\t\t\t$word = '';\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tlist(, $rand_index) = unpack('C', $bytes[$byte_index++]);\r\n\t\t\t\t\tif ($rand_index &gt; $rand_max)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t$word .= $pool[$rand_index];\r\n\t\t\t\t\t$word_index++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (empty($word))\r\n\t\t{\r\n\t\t\tfor ($i = 0; $i &lt; $word_length; $i++)\r\n\t\t\t{\r\n\t\t\t\t$word .= $pool[mt_rand(0, $rand_max)];\r\n\t\t\t}\r\n\t\t}\r\n\t\telseif ( ! is_string($word))\r\n\t\t{\r\n\t\t\t$word = (string) $word;\r\n\t\t}\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/ Determine angle and position\r\n\t\t\/\/ -----------------------------------\r\n\t\t$length\t= strlen($word);\r\n\t\t$angle\t= ($length &gt;= 6) ? mt_rand(-($length-6), ($length-6)) : 0;\r\n\t\t$x_axis\t= mt_rand(6, (360\/$length)-16);\r\n\t\t$y_axis = ($angle &gt;= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height);\r\n\r\n\t\t\/\/ Create image\r\n\t\t\/\/ PHP.net recommends imagecreatetruecolor(), but it isn't always available\r\n\t\t$im = function_exists('imagecreatetruecolor')\r\n\t\t\t? imagecreatetruecolor($img_width, $img_height)\r\n\t\t\t: imagecreate($img_width, $img_height);\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/  Assign colors\r\n\t\t\/\/ ----------------------------------\r\n\r\n\t\tis_array($colors) OR $colors = $defaults['colors'];\r\n\r\n\t\tforeach (array_keys($defaults['colors']) as $key)\r\n\t\t{\r\n\t\t\t\/\/ Check for a possible missing value\r\n\t\t\tis_array($colors[$key]) OR $colors[$key] = $defaults['colors'][$key];\r\n\t\t\t$colors[$key] = imagecolorallocate($im, $colors[$key][0], $colors[$key][1], $colors[$key][2]);\r\n\t\t}\r\n\r\n\t\t\/\/ Create the rectangle\r\n\t\tImageFilledRectangle($im, 0, 0, $img_width, $img_height, $colors['background']);\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/  Create the spiral pattern\r\n\t\t\/\/ -----------------------------------\r\n\t\t$theta\t\t= 1;\r\n\t\t$thetac\t\t= 7;\r\n\t\t$radius\t\t= 16;\r\n\t\t$circles\t= 20;\r\n\t\t$points\t\t= 32;\r\n\r\n\t\tfor ($i = 0, $cp = ($circles * $points) - 1; $i &lt; $cp; $i++)\r\n\t\t{\r\n\t\t\t$theta += $thetac;\r\n\t\t\t$rad = $radius * ($i \/ $points);\r\n\t\t\t$x = ($rad * cos($theta)) + $x_axis;\r\n\t\t\t$y = ($rad * sin($theta)) + $y_axis;\r\n\t\t\t$theta += $thetac;\r\n\t\t\t$rad1 = $radius * (($i + 1) \/ $points);\r\n\t\t\t$x1 = ($rad1 * cos($theta)) + $x_axis;\r\n\t\t\t$y1 = ($rad1 * sin($theta)) + $y_axis;\r\n\t\t\timageline($im, $x, $y, $x1, $y1, $colors['grid']);\r\n\t\t\t$theta -= $thetac;\r\n\t\t}\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/  Write the text\r\n\t\t\/\/ -----------------------------------\r\n\r\n\t\t$use_font = ($font_path !== '' &amp;&amp; file_exists($font_path) &amp;&amp; function_exists('imagettftext'));\r\n\t\tif ($use_font === FALSE)\r\n\t\t{\r\n\t\t\t($font_size &gt; 5) &amp;&amp; $font_size = 5;\r\n\t\t\t$x = mt_rand(0, $img_width \/ ($length \/ 3));\r\n\t\t\t$y = 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t($font_size &gt; 30) &amp;&amp; $font_size = 30;\r\n\t\t\t$x = mt_rand(0, $img_width \/ ($length \/ 1.5));\r\n\t\t\t$y = $font_size + 2;\r\n\t\t}\r\n\r\n\t\tfor ($i = 0; $i &lt; $length; $i++)\r\n\t\t{\r\n\t\t\tif ($use_font === FALSE)\r\n\t\t\t{\r\n\t\t\t\t$y = mt_rand(0 , $img_height \/ 2);\r\n\t\t\t\timagestring($im, $font_size, $x, $y, $word[$i], $colors['text']);\r\n\t\t\t\t$x += ($font_size * 2);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$y = mt_rand($img_height \/ 2, $img_height - 3);\r\n\t\t\t\timagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]);\r\n\t\t\t\t$x += $font_size;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\/\/ Create the border\r\n\t\timagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $colors['border']);\r\n\r\n\t\t\/\/ -----------------------------------\r\n\t\t\/\/  Generate the image\r\n\t\t\/\/ -----------------------------------\r\n\t\t$img_url = rtrim($img_url, '\/').'\/';\r\n\r\n\t\tif (function_exists('imagejpeg'))\r\n\t\t{\r\n\t\t\t$img_filename = $now.'.jpg';\r\n\t\t\timagejpeg($im, $img_path.$img_filename);\r\n\t\t}\r\n\t\telseif (function_exists('imagepng'))\r\n\t\t{\r\n\t\t\t$img_filename = $now.'.png';\r\n\t\t\timagepng($im, $img_path.$img_filename);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\treturn FALSE;\r\n\t\t}\r\n\r\n\t\t$img = '&lt;img '.($img_id === '' ? '' : 'id=\"'.$img_id.'\"').' src=\"'.$img_url.$img_filename.'\" style=\"width: '.$img_width.'; height: '.$img_height .'; border: 0;\" alt=\" \" \/&gt;';\r\n\t\tImageDestroy($im);\r\n\r\n\t\treturn array('word' =&gt; $word, 'time' =&gt; $now, 'image' =&gt; $img, 'filename' =&gt; $img_filename);\r\n\t}\r\n}\r\n<\/pre>\n<p>Notifications_model<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');\r\n\r\n\/**\r\n * Notifications Model\r\n *\r\n * This model handles notifications module data\r\n *\r\n * @package     institutebit\r\n\r\n*\/\r\n\r\nclass Notifications_model extends CI_Model {\r\n\r\n\t\/**\r\n     * Constructor\r\n     *\/\r\n\tfunction __construct()\r\n    {\r\n        parent::__construct();\r\n    }\r\n\r\n    \/**\r\n     * @vars\r\n     *\/\r\n    private $table = 'notifications';\r\n\r\n    \/**\r\n     * get_notifications\r\n     *\r\n     * @return array\r\n     *\r\n     **\/\r\n    public function get_notifications($users_id = NULL)\r\n    {\r\n        $query = \"SELECT `id` FROM $this-&gt;table WHERE `users_id` = '1' GROUP BY `n_type`\";\r\n\r\n        if( $this-&gt;db-&gt;simple_query($query) )\r\n        {\r\n            \/\/ safe mode is off\r\n            $select = array(\r\n                            \"$this-&gt;table.id\",\r\n                            \"COUNT($this-&gt;table.n_type) as total\",\r\n                            \"$this-&gt;table.n_type\",\r\n                            \"$this-&gt;table.n_content\",\r\n                            \"$this-&gt;table.n_url\",\r\n                            \"$this-&gt;table.date_added\",\r\n                        );\r\n        }\r\n        else\r\n        {\r\n            \/\/ safe mode is on\r\n            $select = array(\r\n                            \"ANY_VALUE($this-&gt;table.id) as id\",\r\n                            \"COUNT($this-&gt;table.n_type) as total\",\r\n                            \"$this-&gt;table.n_type\",\r\n                            \"ANY_VALUE($this-&gt;table.n_content) as n_content\",\r\n                            \"ANY_VALUE($this-&gt;table.n_url) as n_url\",\r\n                            \"ANY_VALUE($this-&gt;table.date_added) as date_added\",\r\n                        );\r\n        }\r\n\r\n        return     $this-&gt;db-&gt;select($select)\r\n                            -&gt;where(array(\"$this-&gt;table.users_id\"=&gt;$users_id))\r\n                            -&gt;group_by(\"$this-&gt;table.n_type\")\r\n                            -&gt;get($this-&gt;table)\r\n                            -&gt;result();\r\n    }\r\n\r\n    \/**\r\n     * save_notifications\r\n     *\r\n     * @return array\r\n     *\r\n     **\/\r\n    public function save_notifications($data = array())\r\n    {\r\n        $this-&gt;db-&gt;insert($this-&gt;table, $data);\r\n        return $this-&gt;db-&gt;insert_id();\r\n    }\r\n\r\n    \/**\r\n     * delete_notifications\r\n     *\r\n     * @return array\r\n     *\r\n     **\/\r\n    public function delete_notifications($n_type = NULL, $users_id = NULL)\r\n    {\r\n        if($n_type &amp;&amp; $users_id) \/\/ update\r\n            $this-&gt;db-&gt;delete($this-&gt;table, array('n_type' =&gt; $n_type, 'users_id'=&gt;$users_id));\r\n\r\n        if($this-&gt;db-&gt;affected_rows())\r\n            return TRUE;\r\n\r\n        return FALSE;\r\n    }\r\n\r\n}\r\n\r\n\/* Notifications model ends*\/\r\n<\/pre>\n<p>Database<\/p>\n<pre class=\"lang:default decode:true \">CREATE TABLE `notifications` (\r\n  `id` int(11) NOT NULL,\r\n  `n_type` enum('batches','events','bbookings','ebookings','contacts','users','b_cancellation','e_cancellation') DEFAULT NULL,\r\n  `n_content` varchar(128) DEFAULT NULL,\r\n  `n_url` text,\r\n  `is_read` tinyint(1) NOT NULL DEFAULT '0',\r\n  `users_id` int(11) DEFAULT NULL,\r\n  `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\r\nALTER TABLE `notifications`\r\n  ADD PRIMARY KEY (`id`);\r\n\r\nALTER TABLE `notifications`\r\n  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;\r\n\r\nCREATE TABLE `captcha` (\r\n  `captcha_id` bigint(13) UNSIGNED NOT NULL,\r\n  `captcha_time` int(10) UNSIGNED DEFAULT NULL,\r\n  `ip_address` varchar(16) NOT NULL DEFAULT '0',\r\n  `word` varchar(20) DEFAULT NULL\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\r\nALTER TABLE `captcha`\r\n  ADD PRIMARY KEY (`captcha_id`),\r\n  ADD KEY `word` (`word`);\r\n\r\nALTER TABLE `captcha`\r\n  MODIFY `captcha_id` bigint(13) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contact Controller &lt;?php defined(&#8216;BASEPATH&#8217;) OR exit(&#8216;No direct script access allowed&#8217;); class Contact extends Public_Controller { \/** * Constructor *\/ function __construct() { parent::__construct(); \/\/ load the model file $this-&gt;load-&gt;model(&#8216;contact_model&#8217;); $this-&gt;load-&gt;model(&#8216;notifications_model&#8217;); \/\/ load the captcha helper $this-&gt;load-&gt;helper(&#8216;captcha&#8217;); } \/************************************************************************************** * PUBLIC FUNCTIONS **************************************************************************************\/ \/** * Default *\/ public function index() { \/\/ validators $this-&gt;form_validation-&gt;set_error_delimiters($this-&gt;config-&gt;item(&#8216;error_delimeter_left&#8217;), $this-&gt;config-&gt;item(&#8216;error_delimeter_right&#8217;)); $this-&gt;form_validation-&gt;set_rules(&#8216;name&#8217;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Sample Contact Form with validation, Captcha &amp; Notification - Codeigniter<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sample Contact Form with validation, Captcha &amp; Notification - Codeigniter\" \/>\n<meta property=\"og:description\" content=\"Contact Controller &lt;?php defined(&#039;BASEPATH&#039;) OR exit(&#039;No direct script access allowed&#039;); class Contact extends Public_Controller { \/** * Constructor *\/ function __construct() { parent::__construct(); \/\/ load the model file $this-&gt;load-&gt;model(&#039;contact_model&#039;); $this-&gt;load-&gt;model(&#039;notifications_model&#039;); \/\/ load the captcha helper $this-&gt;load-&gt;helper(&#039;captcha&#039;); } \/************************************************************************************** * PUBLIC FUNCTIONS **************************************************************************************\/ \/** * Default *\/ public function index() { \/\/ validators $this-&gt;form_validation-&gt;set_error_delimiters($this-&gt;config-&gt;item(&#039;error_delimeter_left&#039;), $this-&gt;config-&gt;item(&#039;error_delimeter_right&#039;)); $this-&gt;form_validation-&gt;set_rules(&#039;name&#039;, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/\" \/>\n<meta property=\"og:site_name\" content=\"Codeigniter\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-31T06:50:28+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/\",\"url\":\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/\",\"name\":\"Sample Contact Form with validation, Captcha & Notification - Codeigniter\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/codeigniter\/#website\"},\"datePublished\":\"2019-01-31T06:50:28+00:00\",\"dateModified\":\"2019-01-31T06:50:28+00:00\",\"author\":{\"@id\":\"\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/codeigniter\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sample Contact Form with validation, Captcha &#038; Notification\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/codeigniter\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/codeigniter\/\",\"name\":\"Codeigniter\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/codeigniter\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sample Contact Form with validation, Captcha & Notification - Codeigniter","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/","og_locale":"en_US","og_type":"article","og_title":"Sample Contact Form with validation, Captcha & Notification - Codeigniter","og_description":"Contact Controller &lt;?php defined('BASEPATH') OR exit('No direct script access allowed'); class Contact extends Public_Controller { \/** * Constructor *\/ function __construct() { parent::__construct(); \/\/ load the model file $this-&gt;load-&gt;model('contact_model'); $this-&gt;load-&gt;model('notifications_model'); \/\/ load the captcha helper $this-&gt;load-&gt;helper('captcha'); } \/************************************************************************************** * PUBLIC FUNCTIONS **************************************************************************************\/ \/** * Default *\/ public function index() { \/\/ validators $this-&gt;form_validation-&gt;set_error_delimiters($this-&gt;config-&gt;item('error_delimeter_left'), $this-&gt;config-&gt;item('error_delimeter_right')); $this-&gt;form_validation-&gt;set_rules('name', [&hellip;]","og_url":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/","og_site_name":"Codeigniter","article_published_time":"2019-01-31T06:50:28+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/","url":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/","name":"Sample Contact Form with validation, Captcha & Notification - Codeigniter","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/codeigniter\/#website"},"datePublished":"2019-01-31T06:50:28+00:00","dateModified":"2019-01-31T06:50:28+00:00","author":{"@id":""},"breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/codeigniter\/sample-contact-form-with-validation-captcha-notification\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/codeigniter\/"},{"@type":"ListItem","position":2,"name":"Sample Contact Form with validation, Captcha &#038; Notification"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/codeigniter\/#website","url":"https:\/\/www.onlinenote.in\/codeigniter\/","name":"Codeigniter","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/codeigniter\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/posts\/54"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/posts\/54\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/codeigniter\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}