Welcome Guest, Not a member yet? Register   Sign In
Form Validation
#1

[eluser]invision[/eluser]
Hi,

I'm playing about with some very basic form validaton for a web site.

However, currently when the fields are empty and I submit my form, the message outputted is:

Code:
The cname field is required.

The telno field is required.

The email field is required.

This happens because I use <?php echo $this->validation->error_string; ?> in my form view.
Is there a way I could change this, so instead of saying each error, it would put a red border on the input element required?

Would this be in the Validation class somewhere or the Form Helper?



Controller:
Code:
class Createaccount extends Controller {

  function Createaccount()
  {
      parent::Controller();  
  }
  
  function index()
  {  
  $data[‘page_data’] = $this->MPages->getPageBySlug(‘createaccount’);
  $data[‘title’] = $data[‘page_data’][‘title’];
  $data[‘body’] = $data[‘page_data’][‘body’];
  
  #Validations
  $rules[‘cname’] = “required”;
  $rules[‘telno’] = “required”;
  $rules[‘email’] = “required|valid_email”;

$this->validation->set_rules($rules);
  
  #Input and textarea field attributes
  $data[“cname”] = array(‘name’ => ‘cname’, ‘id’ => ‘cname’);
  $data[“telno”] = array(‘name’ => ‘telno’, ‘id’ => ‘telno’);
  $data[‘email’] = array(‘name’ => ‘email’, ‘id’ => ‘email’);

if ($this->validation->run() == FALSE)
      {
  //$this->load->view(‘form_view’, $data);
  $data[‘main’] = ‘public_createaccount’;
    $this->load->vars($data);  
    $this->load->view(‘template’);
      }
      else
      {
        $fname = $this->input->post(‘fname’);
        $email = $this->input->post(‘email’);
        $comments = $this->input->post(‘comments’);
        
        $message = “$fname ($email) had this to say:\n\n$comments”;
        $this->email->from($email, $fname);
        $this->email->to(‘[email protected]’);
        
        $this->email->subject(‘Account Creation’);
        $this->email->message($message);
        
        $this->email->send();
        
        $this->load->view(‘account_success’);
      }

}
  
}
[b]View:[/b]
[code]
<?php echo $this->validation->error_string; ?>
  <?php echo form_open(‘createaccount/index’); ?>
  <label for=“cname”>Company Name: </label>
&lt;?php echo form_input($cname); ?&gt;
  <label for=“telno”>Telephone No.: </label>
&lt;?php echo form_input($telno); ?&gt;
  <label for=“faxno”>Fax No.</label>
&lt;?php echo form_input($faxno); ?&gt;
  <label for=“email”>E-mail</label>
&lt;?php echo form_input($email); ?&gt;
  &lt;?php echo form_submit(‘submit’, ‘Submit’); ?&gt;
  &lt;?php echo form_close(); ?&gt;



Many thanks for any pointers.


Messages In This Thread
Form Validation - by El Forum - 04-19-2010, 02:31 AM
Form Validation - by El Forum - 04-19-2010, 02:41 AM
Form Validation - by El Forum - 04-19-2010, 02:53 AM
Form Validation - by El Forum - 04-19-2010, 03:08 AM
Form Validation - by El Forum - 04-19-2010, 03:10 AM
Form Validation - by El Forum - 04-19-2010, 03:22 AM
Form Validation - by El Forum - 04-19-2010, 03:22 AM
Form Validation - by El Forum - 04-19-2010, 03:34 AM
Form Validation - by El Forum - 04-19-2010, 03:43 AM
Form Validation - by El Forum - 04-19-2010, 03:47 AM
Form Validation - by El Forum - 04-19-2010, 04:05 AM
Form Validation - by El Forum - 04-19-2010, 04:31 AM
Form Validation - by El Forum - 04-19-2010, 04:47 AM
Form Validation - by El Forum - 04-19-2010, 06:31 AM
Form Validation - by El Forum - 04-19-2010, 06:37 AM
Form Validation - by El Forum - 04-19-2010, 06:43 AM
Form Validation - by El Forum - 04-19-2010, 06:50 AM
Form Validation - by El Forum - 04-19-2010, 06:54 AM
Form Validation - by El Forum - 04-19-2010, 06:54 AM
Form Validation - by El Forum - 04-19-2010, 07:17 PM
Form Validation - by El Forum - 04-19-2010, 10:01 PM
Form Validation - by El Forum - 04-20-2010, 01:10 AM
Form Validation - by El Forum - 04-21-2010, 11:05 AM
Form Validation - by El Forum - 04-21-2010, 11:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB