Welcome Guest, Not a member yet? Register   Sign In
[Closed] Codeigniter Validation Question
#11

[eluser]Tim Brownlaw[/eluser]
[quote author="riwakawd" date="1399594339"]
I want to be able to do it via server side can do it with input highlighted 'has-error' but the only issue I am having, is if input is filled in correct should be highlighted 'has-success'.

Currently when use this <?php echo (validation_errors() != '')? 'has-error':'has-success'; ?> makes the input always highlighted 'has-success' when no error.

if there was away to addClass and removeClass using that would be good. Working like the javascript but using codeigniter validation.[/quote]

That is correct!

So let's see... You only want the success or fail class to be "inserted" After the form has been posted/submitted?

So where does that happen? And that is where you would set your class values...

As another hint... you'd could have...
In your Form View
Code:
<div&lt;?php echo $div_name_class;?&gt;> Stuff here </div>

Then in your Controller - check to see.
1. If the Form is submitted AND it's a success
Code:
$form['div_name_class'] = ' class="my-success-class"';
2. if the Form is submitted AND it's a fail...
Code:
$form['div_name_class'] = ' class="you-muffed-it-fella-class"';
3. The Form is NOT Submitted
Code:
$form['div_name_class']  = '';

Of course you can do more clever things in achieving that, but that's the basics!

Cheers
Tim


#12

[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1399618562"][quote author="riwakawd" date="1399594339"]
I want to be able to do it via server side can do it with input highlighted 'has-error' but the only issue I am having, is if input is filled in correct should be highlighted 'has-success'.

Currently when use this &lt;?php echo (validation_errors() != '')? 'has-error':'has-success'; ?&gt; makes the input always highlighted 'has-success' when no error.

if there was away to addClass and removeClass using that would be good. Working like the javascript but using codeigniter validation.[/quote]

That is correct!

So let's see... You only want the success or fail class to be "inserted" After the form has been posted/submitted?

So where does that happen? And that is where you would set your class values...

As another hint... you'd could have...
In your Form View
Code:
<div&lt;?php echo $div_name_class;?&gt;> Stuff here </div>

Then in your Controller - check to see.
1. If the Form is submitted AND it's a success
Code:
$form['div_name_class'] = ' class="my-success-class"';
2. if the Form is submitted AND it's a fail...
Code:
$form['div_name_class'] = ' class="you-muffed-it-fella-class"';
3. The Form is NOT Submitted
Code:
$form['div_name_class']  = '';

Of course you can do more clever things in achieving that, but that's the basics!

Cheers
Tim


[/quote]

Hi my checked box not validating errors not showing up on the view page? Should do but not same as the codeigniter user guide

Code:
<div class="panel panel-default">
<div class="panel-body">
&lt;?php echo form_open('install/stage_1/index');?&gt;
&lt;?php echo validation_errors('<p class="error">', '</p>'); ?&gt;
<div class="form-group">
<div class="terms"  scroll; height: 550px;">&lt;?php echo $text_terms; ?&gt;</div>
</div>
<div class="form-group">
&lt;?php
$data = array(
    'name'  => 'terms',
    'id'          => 'terms',
    'value'       => '1',
    'checked'     => FALSE,
    'style' => 'margin-right: 10px;'
    );

echo form_checkbox($data);
$data = array(
    'value'       => $button_continue,
    'role'       => 'button',
    'type' => 'submit',
    'class' => 'btn btn-primary'
    );
echo form_submit($data);
?&gt;
</div>

<div class="form-group">
</div>
&lt;?php echo form_close();?&gt;
</div>
</div>

Controller

Code:
public function index() {

$data = array();
$this->load->helper('form');
$this->load->library('form_validation');

$this->form_validation->set_rules('terms', 'Agree to License', 'required');

if ($this->form_validation->run() == FALSE) {
    $data = array();
    $data['heading_step_1'] = $this->lang->line('heading_step_1');
    $data['heading_step_1_small'] = $this->lang->line('heading_step_1_small');
    $data['text_license'] = $this->lang->line('text_license');
    $data['text_installation'] = $this->lang->line('text_installation');
    $data['text_configuration'] = $this->lang->line('text_configuration');
    $data['text_finished'] = $this->lang->line('text_finished');
    $data['text_project'] = $this->lang->line('text_project');
    $data['text_documentation'] = $this->lang->line('text_documentation');
    $data['text_footer'] = $this->lang->line('text_footer');
    $data['text_support'] = $this->lang->line('text_support');
    $data['button_continue'] = $this->lang->line('button_continue');
    $data['text_terms'] = $this->lang->line('text_terms');

    $this->load->view('template/stage_1', $data);

} else {

    redirect('install/stage_2');

}
  
}
#13

[eluser]riwakawd[/eluser]
I have fixed issue with checked validation I had to remove the else I don't know why I had to do that. Must be a bug with CI it was done via user guide but fixed it.

Code:
public function agree() {
  $data = array();

      $this->form_validation->set_rules('accept', 'Agree to License', 'trim|required');
      $this->form_validation->set_message('required', 'You must agree to the license before you can install!');

      if ($this->form_validation->run()) {
            redirect('install/step2');
      }

      $data = array();
  $data['heading_step_1'] = $this->lang->line('heading_step_1');
  $data['heading_step_1_small'] = $this->lang->line('heading_step_1_small');
  $data['text_license'] = $this->lang->line('text_license');
  $data['text_installation'] = $this->lang->line('text_installation');
  $data['text_configuration'] = $this->lang->line('text_configuration');
  $data['text_finished'] = $this->lang->line('text_finished');
  $data['text_project'] = $this->lang->line('text_project');
  $data['text_documentation'] = $this->lang->line('text_documentation');
  $data['text_footer'] = $this->lang->line('text_footer');
  $data['text_support'] = $this->lang->line('text_support');
  $data['button_continue'] = $this->lang->line('button_continue');
  $data['text_terms'] = $this->lang->line('text_terms');

  $this->load->view('template/stage_1', $data);

  }
#14

[eluser]Tim Brownlaw[/eluser]
Well now this is a different issue and you're jumping around in the code from an index method to an agree method and as we've no idea as to what other code is, or was there... it's rather hard to tell!

One thing I am concerned about is...
Quote:I have fixed issue with checked validation I had to remove the else I don’t know why I had to do that. Must be a bug with CI it was done via user guide but fixed it.

Find out why! There's always a reason and being able to work out the why's will help you as you get further along... Always know WHY!





Theme © iAndrew 2016 - Forum software by © MyBB