Try to achieve a contact form on the contact page and do not yet understand where to put the email address where you can receive email when someone sends one. I need help.
My code is this
Code:
class Website extends CI_Controller {
public function __construct ()
{
parent::__construct();
}
public function index() {
$this->load->view('pages/contact');
}
public function submission() {
if (!$this->input->is_ajax_request()) { exit('no valid request.'); }
$config = array(
array(
'field' => 'name',
'label' => 'Your name',
'rules' => 'trim|required|xss_clean|min_length[3]|max_length[50]'
),
array(
'field' => 'email',
'label' => 'Email Address',
'rules' => 'trim|required|min_length[5]|max_length[30]|valid_email'
),
array(
'field' => 'message',
'label' => 'Message',
'rules' => 'trim|required|xss_clean|min_length[5]'
),
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == TRUE)
{
echo '<div class="control-succes">Your message is send!</div>';
}
else
{
echo '<div class="errors">'.validation_errors().'</div>';
}
}
//custom validation function to accept only alphabets and space input
public function alpha_space_only($str) {
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
and contact.php code
Code:
<h3>Give us a message</h3>
<?php echo form_open('website/submission', array('class'=>'jsform')); ?>
<p><input type="text" name="name" placeholder="Name"></p>
<p><input type="text" name="email" placeholder="Valid Email"></p>
<p><textarea rows="4" cols="37" name="message" placeholder="Enter text here..."></textarea></p>
<p><input type="submit" value="Send message" class="btn btn-default"></p>
<?php echo form_close(); ?>