Welcome Guest, Not a member yet? Register   Sign In
form validation
#1

[eluser]talwinder[/eluser]
Hi, I am trying to validate my form. The validation is working properly but i am unable to echo the error messages individualy. here is the code of my view file.


$nameLabel = array('id' => 'nameLabel', 'for' => 'name');
echo form_label('Name','', $nameLabel);


$nameInput = array('id' => 'name', 'name' => 'name');
echo form_input($nameInput);
echo form_error('name');


please help


Thanks
#2

[eluser]InsiteFX[/eluser]
Code:
<?php echo form_error(‘name’);?>

InsiteFX
#3

[eluser]talwinder[/eluser]
yeh i am already using echo in the php tags.
#4

[eluser]InsiteFX[/eluser]
Then you have soething else wrong in your code, you will need to show your code so that we can help you!

and please use code tags remove the spaces in the tags.
Code:
[code ]

[/code ]

InsiteFX
#5

[eluser]talwinder[/eluser]
---------- HERE IS THE CODE OF MY VIEW FILE---------------

<section id="content">
&lt;?php
echo heading('Contact Me', 1);
echo form_open('site/contact', 'id="contact"');
echo form_fieldset();


$nameLabel = array('id' => 'nameLabel', 'for' => 'name');
echo form_label('Name','', $nameLabel);


$nameInput = array('id' => 'name', 'name' => 'name');
echo form_input($nameInput);
echo form_error('name');

$subLabel = array('id' => 'subLabel', 'for' => 'subject');
echo form_label('Subject','', $subLabel);


$subjectInput = array('id' => 'subject', 'name' => 'subject');
echo form_input($subjectInput);
echo form_error('subject');


$telLabel = array('id' => 'telLabel', 'for' => 'tel');
echo form_label('Phone','', $telLabel);
echo form_error('tel');
$telInput = array('id' => 'tel', 'name' => 'tel', 'type' => 'tel');
echo form_input($telInput);


$emailLabel = array('id' => 'emailLabel', 'for' => 'email');
echo form_label('Email','', $emailLabel);


$emailInput = array('id' => 'email', 'name' => 'email', 'type' => 'email');
echo form_input($emailInput);
echo form_error('email');

$messageLabel = array('id' => 'messageLabel', 'for' => 'message');
echo form_label('Message','', $messageLabel);

echo form_textarea('message', '', 'id="message"', 'name="message"');

$submit = array('id' => 'submit', 'name' => 'submit', 'value' => ' ', 'type' => 'submit');
echo form_input($submit);
echo form_fieldset_close();
echo form_close();


?&gt;

</section>&lt;!--end of content--&gt;



--------------HERE IS THE CODE OF MY CONTROLLER FUNCTION-----------

function contact(){
$data['mainContent'] = 'contact';
$this->load->view('includes/template', $data);

$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required');
$this->form_validation->set_rules('tel', 'Phone', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

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


}else{

$this->siteModel->addEnquiry();

}
#6

[eluser]j4zzyh4ck3r[/eluser]
[quote author="talwinder" date="1302506073"]---------- HERE IS THE CODE OF MY VIEW FILE---------------

<section id="content">
&lt;?php
echo heading('Contact Me', 1);
echo form_open('site/contact', 'id="contact"');
echo form_fieldset();


$nameLabel = array('id' => 'nameLabel', 'for' => 'name');
echo form_label('Name','', $nameLabel);


$nameInput = array('id' => 'name', 'name' => 'name');
echo form_input($nameInput);
echo form_error('name');

$subLabel = array('id' => 'subLabel', 'for' => 'subject');
echo form_label('Subject','', $subLabel);


$subjectInput = array('id' => 'subject', 'name' => 'subject');
echo form_input($subjectInput);
echo form_error('subject');


$telLabel = array('id' => 'telLabel', 'for' => 'tel');
echo form_label('Phone','', $telLabel);
echo form_error('tel');
$telInput = array('id' => 'tel', 'name' => 'tel', 'type' => 'tel');
echo form_input($telInput);


$emailLabel = array('id' => 'emailLabel', 'for' => 'email');
echo form_label('Email','', $emailLabel);


$emailInput = array('id' => 'email', 'name' => 'email', 'type' => 'email');
echo form_input($emailInput);
echo form_error('email');

$messageLabel = array('id' => 'messageLabel', 'for' => 'message');
echo form_label('Message','', $messageLabel);

echo form_textarea('message', '', 'id="message"', 'name="message"');

$submit = array('id' => 'submit', 'name' => 'submit', 'value' => ' ', 'type' => 'submit');
echo form_input($submit);
echo form_fieldset_close();
echo form_close();


?&gt;

</section>&lt;!--end of content--&gt;



--------------HERE IS THE CODE OF MY CONTROLLER FUNCTION-----------

function contact(){
$data['mainContent'] = 'contact';
$this->load->view('includes/template', $data);

$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required');
$this->form_validation->set_rules('tel', 'Phone', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

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


}else{

$this->siteModel->addEnquiry();

}[/quote]

Code:
if($this->form_validation->run() == FALSE){
       // put your form view here
      
      }else{
      
        $this->siteModel->addEnquiry();
      
      }

You forget to load your view to validate all fields, try to load your form view there...
#7

[eluser]InsiteFX[/eluser]
Hes loading his view but in the wrong place!
Code:
function contact(){
      $data['mainContent'] = 'contact';
      
      $this->load->library('form_validation');
      $this->form_validation->set_rules('name', 'Name', 'trim|required');
      $this->form_validation->set_rules('subject', 'Subject', 'trim|required');
      $this->form_validation->set_rules('tel', 'Phone', 'trim|required');
      $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  
      if($this->form_validation->run() == FALSE){
        
         $this->load->view('includes/template', $data);

      }else{
        
        $this->siteModel->addEnquiry();
        
        $this->load->view('Success', $data);
      }

And next time please use the CODE TAGS! Like I showed you above.

If you can not do that then use POST REPLY which will give you a complete editor for this!

I do not like going through others code and changing all the wrong ''

InsiteFX
#8

[eluser]talwinder[/eluser]
thanks 4 help.. it works!!.. no worries i will make sure that i use code tags for code Smile




Theme © iAndrew 2016 - Forum software by © MyBB