• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$this->form_validation->run() returns FALSE

#1
PHP Code:
// save
    public function insert() {
    $this->load->helper('form');
        $this->load->library('form_validation');


// set validation rules
    $rules = array(
        array('field' => 'name',
              'label' => 'Full Name',
              'rules' => 'trim|required|min_length[4]|max_length[16]') ,
        array('field' => 'email',
              'label' => 'Enter your Email',
              'rules' => 'trim|required|valid_email|min_length[6]|max_length[60]'),
        array('field' => 'subject',
              'label' => 'Enter your Subject',
              'rules' => 'trim|required|min_length[6]|max_length[60]'),
        array('field' => 'message',
              'label' => 'Enter your Message',
              'rules' => 'trim|required|min_length[12]|max_length[200]')
      ) ;

    $this->form_validation->set_rules($rules);




        if ($this->form_validation->run() == TRUE){

        // user    
        $data['name'] = $this->input->post('name'true);
        $data['email'] = $this->input->post('email'true);      
        $data
['subject'] = $this->input->post('subject'true);      
        $data
['message'] = $this->input->post('message'true);          
        
        $sendEmail 
$this->Insert_model->insert_data('tbl_contact'$data);



        if ($sendEmail)
        {
            $this->session->set_flashdata('msg','<div class="alert alert-success">Mail sent!</div>');

            redirect('home/contact');
        } else {
            $this->session->set_flashdata('msg','<div class="alert alert-danger">Problem in sending</div>');
            $this->load->view('home/contact');
        }



        }else{


        echo "ERrorrrr";


        }




    }
    
    
    

Reply

#2
Please run this code and post the results after you have filled in the form.
PHP Code:
echo '<pre>'var_dump($this->input->post()); echo '</pre>'
Reply

#3
Here is my view page.
Code:
<form class="form-horizontal form-stripe" action="<?php echo base_url(); ?>contact/insert" method="POST" >
            <div class="form-group">
              <?php echo validation_errors(); ?>
              
            </div>
            <div class="form-group">
              <div class="contact-form">
                <label for="">Your name</label>
                <input name="name" id="name" class="form-control" value="<?php echo set_value('name'); ?>" placeholder="Type your Name" onfocus="this.placeholder=''" onblur="this.placeholder='Type your Name'" type="text">
                
                <?php echo form_error('name', '<span class="text-danger">','</span>'); ?>
              </div>
            </div>
            <div class="form-group">
              <div class="contact-form">
                <label for="">Your Email</label>
                <input name="email" id="email" value="<?php echo set_value('email'); ?>"  class="form-control" placeholder="Type your Email" onfocus="this.placeholder=''" onblur="this.placeholder='Type your Email'" type="email">
                <?php echo form_error('email', '<span class="text-danger">','</span>'); ?>
              </div>
            </div>
            <div class="form-group">
              <div class="contact-form">
                <label for="">Subject</label>
                <input name="subject" id="subject" class="form-control" value="<?php echo set_value('subject'); ?>" placeholder="Subject here" onfocus="this.placeholder=''" onblur="this.placeholder='Subject here'" type="subject">
                <?php echo form_error('subject', '<span class="text-danger">','</span>'); ?>
              </div>
            </div>
            <div class="form-group">
              <div class="contact-form">
                <label for="">Your Message</label>
                <textarea name="message" id="message" cols="5" rows="5" class="form-control" placeholder="Type your message here please" onfocus="this.placeholder=''" onblur="this.placeholder='Type your message here please'"><?php echo set_value('message'); ?></textarea>
                <?php echo form_error('message', '<span class="text-danger">','</span>'); ?>
              </div>
            </div>
            <div class="form-group">
              <div class="contact-form">
                <button type="submit" name="submit" class="btn btn-primary btn-elements">Submit</button>
              </div>
            </div>


          </form>
Reply

#4
Why did not insert my message in Database? But false is working .

array(5) {
["name"]=>
string(18) "Md Nababur Rahaman"
["email"]=>
string(19) "[email protected]"
["subject"]=>
string(48) "How can i show individual tag id from tags array"
["message"]=>
string(37) "dssdf sdf df sd sdfsd a sf sdfsdfs fd"
["submit"]=>
string(0) ""
}
Reply

#5
You mean that if you do an var_dump here? You have your data?
PHP Code:
$data['name'] = $this->input->post('name'true);
$data['email'] = $this->input->post('email'true);      
$data['subject'] = $this->input->post('subject'true);      
$data['message'] = $this->input->post('message'true); 
var_dump($data);exit; 

If so, it's your insert model. Not the validation as you said earlier.
Reply

#6
I want to insert form on my database with input validation data.
Reply

#7
Its work now thanks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.