Welcome Guest, Not a member yet? Register   Sign In
Please help with form
#1

[eluser]ppwalks[/eluser]
I am building a form on a website to submit user information, the problem i'm having is that the captcha is not stopping the form from submitting, I have followed instructions on using cl captcha and all seemed to be well until I relised it was not stopping the form submission.

Also once the form has been submitted and the validated select boxes reset to default state i can submit the form a second time before the validation routine applies again which is strange, please can somebody help me!

My controller code:

Code:
function index()
{
  
  $data['title'] = "Some title";
  $data['main'] = 'view_file';
  $data['side'] = 'advert';
    $data["cap_img"] = $this ->_make_captcha();
  $this->load->helper(array('form', 'url'));
  $this->load->plugin('captcha');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('name', 'name', 'required|min_length[3]');
  $this->form_validation->set_rules('email', 'email', 'required|valid_email');
  $this->form_validation->set_rules('homeTel', 'Telephone', 'required|numeric|min_length[9]|is_uk_num');
  $this->form_validation->set_rules('workTel', 'Telephone', 'required|numeric|min_length[9]|is_uk_num');
  $this->form_validation->set_rules('movingDate', 'Moving Date', 'required');
  $this->form_validation->set_rules('house_num_from', 'House Number From', 'required');
  $this->form_validation->set_rules('house_num_to', 'House Number To', 'required');
  $this->form_validation->set_rules('street_from', 'Street From', 'required');
  $this->form_validation->set_rules('street_to', 'Street To', 'required');
  $this->form_validation->set_rules('city_to', 'City To', 'required');
  $this->form_validation->set_rules('city_from', 'City From', 'required');
  $this->form_validation->set_rules('postcode_to', 'Postcode To', 'required|valid_postcode');
  $this->form_validation->set_rules('postcode_from', 'Postcode From', 'required|valid_postcode');
  $this->form_validation->set_rules('myradio', 'Packing Option', 'required');
  $this->form_validation->set_rules('milage', 'Milage', 'required|is_numeric');
  $this->form_validation->set_rules('bedroom_to', 'Bedroom option', 'required|is_numeric|max_length[2]');
  $this->form_validation->set_rules('bedroom_from', 'Bedroom option', 'required|is_numeric|max_length[2]');
  $this->form_validation->set_rules('Property_type_from', 'Property Type', 'required|select_validate');
  $this->form_validation->set_rules('Property_type_to', 'Property Type', 'required|select_validate');
  $this->form_validation->set_rules('accessability_from', 'Accessability', 'required|select_validate');
  $this->form_validation->set_rules('accessability_to', 'Accessability', 'required|select_validate');
    $captcha_result = '';
  if ( $this -> _check_capthca() ) {
         $captcha_result = 'GOOD';
      } else {
        $captcha_result = 'BAD';
      }
   $data["cap_msg"] = $captcha_result;
  

  if ($this->form_validation->run() == FALSE)
  {
  
   $this->load->vars($data);
   $this->load->view('index');
  }
  else
  {
   $data['main'] = 'get_quote';
   $data['side'] = 'advert';
   $this->MAdmins->addSubscriber();
   $this->session->set_flashdata('message','Quoatation Sent, Thankyou');
   $this->load->vars($data);
   $this->load->view('index');
   //$config = Array(
   //'protocol' => 'smtp',
         //'smtp_host' => 'ssl://smtp.googlemail.com',
         //'smtp_port' => 465,
         //'smtp_user' => '[email protected]',
         //'smtp_pass' => 'simplejack',
         //'mailtype'  => 'html',
         //'charset' => 'utf-8',
         //'wordwrap' => TRUE

    //);
  //  $this->load->library('email', $config);
// $this->email->set_mailtype("html");
//   $this->email->set_newline("\r\n");
   // $email_body ="<div>hello world</div>";
    //$this->email->from('[email protected]', 'ddd');

    //$list = array('[email protected]');
    //$this->email->to($list);
    //$this->email->subject('Testing Email');
    //$this->email->message($email_body);

    //$this->email->send();
   // echo $this->email->print_debugger();

  }
}
function _make_captcha()
  {
  $this -> load -> plugin( 'captcha' );
  $vals = array(
    'img_path' => './captcha/', // PATH for captcha ( *Must mkdir (htdocs)/captcha )
    'img_url' => base_url().'/captcha/', // URL for captcha img
    'img_width' => 200, // width
    'img_height' => 60, // height
    'font' => '../../system/fonts/arialbd.ttf',
    'expiration' => 7200 ,
    );
  // Create captcha
  $cap = create_captcha( $vals );
  // Write to DB
  if ( $cap ) {
    $data = array(
      'captcha_id' => '',
      'captcha_time' => $cap['time'],
      'ip_address' => $this -> input -> ip_address(),
      'word' => $cap['word'] ,
      );
    $query = $this -> db -> insert_string( 'captcha', $data );
    $this -> db -> query( $query );
  }else {
    return "Umm captcha not work" ;
  }
  return $cap['image'] ;
  }

  function _check_capthca()
  {
  // Delete old data ( 2hours)
  $expiration = time()-7200 ;
  $sql = " DELETE FROM captcha WHERE captcha_time < ? ";
  $binds = array($expiration);
  $query = $this->db->query($sql, $binds);

  //checking input
  $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
  $binds = array($this->input->post('captcha'), $this->input->ip_address(), $expiration);
  $query = $this->db->query($sql, $binds);
  $row = $query->row();

  if ( $row -> count > 0 )
  {
    return true;
  }
  return false;

  }
  

}

Please if someone knows how this can be fixed then please enlighten me...


Messages In This Thread
Please help with form - by El Forum - 02-16-2012, 09:34 AM
Please help with form - by El Forum - 02-16-2012, 09:38 AM
Please help with form - by El Forum - 02-16-2012, 09:44 AM
Please help with form - by El Forum - 02-16-2012, 10:28 AM
Please help with form - by El Forum - 02-17-2012, 01:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB