EllisLab text mark
Advanced Search
     
validation problem
Posted: 08 August 2009 02:41 PM   [ Ignore ]
Avatar
Joined: 2009-05-23
32 posts

hi,

I am using form validation, but error message is not displayed :(
this is the code

view file

<table class="{class}">
<?php echo $this->validation->error_string?>
<form name="editplan" action="{site_url}index.php/projects/plan_edited" method="post" >
<
tbody>
    <
th colspan="2">{id} {definition}</th>


</
tr>
   <
td align="right">&nbsp;</td>
    <
td >
   <
input value="Commit"  type="button">
   </
td>
</
tbody>
</
form>
</
table

controller file

function edit_plan($plan_id)
    
{
        $data 
tags();
        
$data['tabs']    tabs('projects');
       
        
// get the list of stages
        
$data['states']$this->projects_model->get_nominal_plan($limit$this->uri->segment(4), $plan_id);
        
    
            
// if i don't set it here too, it gives error of  Message: Undefined property: CI_Validation::$commit    
        
$rules['commit']        "required";
        
$this->validation->set_rules($rules);
            
$fields['commit']    'Commit';
        
$this->validation->set_fields($fields);
        
            
$this->parser->parse('projects/edit_plan'$data);  
    
}
    
function plan_edited()
    
{
        $this
->load->helper'form' );
            
$this->load->helper'url' );
        
$this->load->library('validation');
        
$rules['commit']        "required";

        
$this->validation->set_rules($rules);
        
$fields['commit']    'Commit';
            
$this->validation->set_fields($fields);
        if (
$this->validation->run() == FALSE)
        
{
                 
// redirects on form page
         
$pieces explode("index.php"$_SERVER['HTTP_REFERER']); 
         
redirect($pieces[1]);
        
}
        
    } 

Note: this is an edit form

 
Posted: 08 August 2009 03:50 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
511 posts

You don’t assign a name to the form input. e.g.

<input type="text" name="my_commit"

That will make sure the input value will be posted.

It is also better use the correct form_validation library instead of the old validation library which is deprecated

 Signature 

In need for a good host for your Codeigniter Apps? Try Webfaction! It’s fast, reliable, technically sound, in the USA, EU and Asia.

 
Posted: 09 August 2009 04:32 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-23
32 posts

sorry, i had put wrong view page..

{states}
<table class="{class}">
<?php echo $this->validation->error_string?>
<form name="editplan" action="{site_url}index.php/projects/plan_edited" method="post"  >
<
tbody>
    <
th colspan="2">{id} {definition}</th>



<
tr>
   <
td align="right">* Commit:<?php echo $this->validation->commit_error?></td>
   
    <
td >
    <
textarea class="text"  cols="48" name="commit" style="height: 100px;" value="<?php  $this->validation->commit?>" > </textarea><br />
    
    </
td>
    
</
tr>
   <
td align="right">&nbsp;</td>
    <
td >
   <
input value="Commit"  type="button">
   </
td>
</
tbody>
</
form>

</
table>
{/states} 

i’ve also used form_validation, but still not showing error message :(

 
Posted: 09 August 2009 06:10 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
511 posts
alberta - 09 August 2009 08:32 AM

sorry, i had put wrong view page.. i’ve also used form_validation, but still not showing error message :(

It seems that you mess up the order somehow.

It should look like something like this In your controller

function edit_plan($plan_id)
{
  $this
->load->library("form_validation");
  
$fields=array(array('field' => 'commit',
                    
'rules' => 'trim|required'));
  
$this->form_validation->set_rules($fields);
  if (
$this->form_validation->run())
  
{
     
// in case of success
     // do your thing
     // redirect to someplace
  
else
  
{
    
// in case of failure
    // actually you don't have to do anything here
  
}
  
//show the view file of the form including the error message here

And in your view

<?php echo form_error('commit'); ?>
<form name="editplan" action="  <?php /* same url as before */ ?>   " method="post"  >
<
textarea class="text"  cols="48" name="commit" style="height: 100px;" ><?php echo set_value('commit'); ?></textarea
<input value="Commit"  type="button">
</
form

again use the form_validation library. It is a bad idea to use the validation library. Make sure you do everything in the correct order. The manual is very clear on how to use the form_validation library.

 Signature 

In need for a good host for your Codeigniter Apps? Try Webfaction! It’s fast, reliable, technically sound, in the USA, EU and Asia.

 
Posted: 14 August 2009 06:35 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-23
32 posts

thanks,

this code works fine for text fields. but again creating problem for checkboxe. I have written the code in correct format but for checkbox no use. Neither it dispays error message nor goes to succes page even if checkbox is selected.

 
Posted: 14 August 2009 08:19 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
511 posts
alberta - 14 August 2009 10:35 AM

thanks,

this code works fine for text fields. but again creating problem for checkboxe. I have written the code in correct format but for checkbox no use. Neither it dispays error message nor goes to succes page even if checkbox is selected.

Please read the manual. It clearly says :

<input type="checkbox" name="mycheck[]" value="1" <?php echo set_checkbox('mycheck[]''1'); ?> /> 
 Signature 

In need for a good host for your Codeigniter Apps? Try Webfaction! It’s fast, reliable, technically sound, in the USA, EU and Asia.