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

[eluser]alberta[/eluser]
hi,

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

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


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

controller file

Code:
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
#2

[eluser]Clooner[/eluser]
You don't assign a name to the form input. e.g.
Code:
&lt;input type="text" name="my_commit"&gt;
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
#3

[eluser]alberta[/eluser]
sorry, i had put wrong view page..
Code:
{states}
<table class="{class}">
&lt;?php echo $this->validation->error_string; ?&gt;
&lt;form name="editplan" action="{site_url}index.php/projects/plan_edited" method="post"  &gt;
<tbody>
    <th colspan="2">{id} - {definition}</th>



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

</table>
{/states}

i've also used form_validation, but still not showing error message Sad
#4

[eluser]Clooner[/eluser]
[quote author="alberta" date="1249821157"]sorry, i had put wrong view page.. i've also used form_validation, but still not showing error message Sad[/quote]

It seems that you mess up the order somehow.

It should look like something like this In your controller
Code:
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
Code:
&lt;?php echo form_error('commit'); ?&gt;
&lt;form name="editplan" action="  &lt;?php /* same url as before */ ?&gt;   " method="post"  &gt;
&lt;textarea class="text"  cols="48" name="commit" style="height: 100px;" &gt;&lt;?php echo set_value('commit'); ?&gt;&lt;/textarea
&lt;input value="Commit"  type="button">
&lt;/form&gt;

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.
#5

[eluser]alberta[/eluser]
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.
#6

[eluser]Clooner[/eluser]
[quote author="alberta" date="1250260544"]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.[/quote]

Please read the manual. It clearly says :
Code:
&lt;input type="checkbox" name="mycheck[]" value="1" &lt;?php echo set_checkbox('mycheck[]', '1'); ?&gt; /&gt;




Theme © iAndrew 2016 - Forum software by © MyBB