Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Callback Error Message Not Showing Where Should Be
#1

[eluser]riwakawd[/eluser]
I am having trouble with my call back error message it is not showing up where it should be.

It should be showing up above the first input. Were all call back go. But for some reason the call back goes on the same line as the form_error.

I need it all call backs to go where my if error message section is.

How do i fix my call back to get what I am after.

My View


Note: form action does not display on here.
Code:
<form acti echo base_url('install/step_3a');?>" method="post" enctype="multipart/form-data" class="form-horizontal">

<!-- Call Back Error Message -->
<div class="row">
&lt;?php if ($error_warning) { ?&gt;
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> &lt;?php echo $error_warning; ?&gt;
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
&lt;?php } ?&gt;
</div>

<fieldset>

<div class="form-group required">
<label class="col-sm-2 control-label" for="input-username">&lt;?php echo $entry_username; ?&gt;</label>
<div class="col-sm-10">
&lt;?php echo form_input(array('name' => 'username', 'id' => 'username', 'class' => "form-control", 'value' => $username)); ?&gt;
&lt;?php echo form_error('username', '<div class="text-danger">', '</div>'); ?&gt;
</div>
</div>

<div class="form-group required">
<label class="col-sm-2 control-label" for="input-password">&lt;?php echo $entry_password; ?&gt;</label>
<div class="col-sm-10">
&lt;?php echo form_input(array('name' => 'password', 'id' => 'password', 'class' => "form-control", 'value' => set_value('password'))); ?&gt;
&lt;?php echo form_error('password', '<div class="text-danger">', '</div>'); ?&gt;
</div>
</div>

<div class="form-group required">
<label class="col-sm-2 control-label" for="input-email">&lt;?php echo $entry_email; ?&gt;</label>
<div class="col-sm-10">
&lt;?php echo form_input(array('name' => 'email', 'id' => 'email', 'class' => "form-control", 'value' => set_value('email'))); ?&gt;
&lt;?php echo form_error('email', '<div class="text-danger">', '</div>'); ?&gt;
</div>
</div>

</fieldset>

<div class="buttons">
<div class="pull-left">
<a href="&lt;?php echo $back; ?&gt;" class="btn btn-default">&lt;?php echo $button_back; ?&gt;</a>
</div>
<div class="pull-right">
&lt;input type="submit" value="&lt;?php echo $button_continue; ?&gt;" class="btn btn-primary" /&gt;
</div>
</div>

&lt;/form&gt;

My Controller

Code:
&lt;?php

class Step_3a extends CI_Controller {

private $error = array();

public function index() {

  $this->lang->load('install', 'english');

  $data['title'] = 'Configuration';
  
  if ($this->input->server('HTTPS')) {
   $data['base'] = HTTPS_SERVER;
  } else {
   $data['base'] = HTTP_SERVER;
  }

  $this->load->library('form_validation');

  $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|xss_clean|callback_validate');
  $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]');
  $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean');

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

   $this->load->model('model_install');

   $this->model_install->database($this->input->post());

   redirect(site_url('/'));

  } else {

   $data['entry_username'] = "Username";
   $data['entry_password'] = "Password";
   $data['entry_email'] = "Email";

   $data['button_continue'] = "Continue";
   $data['button_back'] = "Back";

   if (array_key_exists('warning', $this->error)) {
    $data['error_warning'] = $this->error['warning'];
   } else {
    $data['error_warning'] = '';
   }

   if (array_key_exists('username', $this->error)) {
    $data['error_username'] = $this->error['username'];
   } else {
    $data['error_username'] = '';
   }

   if (trim($this->input->post('username'))) {
    $data['username'] = $this->input->post('username');
   } else {
    $username = $data['username'] = 'admin';
   }

   $data['back'] = site_url('/');

   $data['header'] = $this->load->view('common/header', $data, true);
   $data['footer'] = $this->load->view('common/footer', null, true);

   $this->load->view('install/step_3a', $data);
  }
}

public function validate() {
  if($this->input->post('username')) {
   $this->error['username'] = $this->form_validation->set_message('validate', 'Please Enter Correct Username Or Password');
  }
  
  return !$this->error;
}
}
#2

[eluser]Tim Brownlaw[/eluser]
Well you are relying on if($error_warning) to evaluate to TRUE or False
Does it?

It seems to be coming back as False which would be the case if I have understood your issue correctly..

Does it get set to anything?

Anything inside an if(...) has to evaluate to Either True or False.

At a guess you need to be testing for it Not being set to an empty string.
Code:
if($error_warning != '' )

To see what it is doing - do a var_dump($error_warning) and test it for when it should show errors and when it shouldn't.

Next part: If you want to have all the errors appear at the top - why not use the inbuilt validation_errors()?
ie
Code:
&lt;?php echo validation_errors(); ?&gt;
#3

[eluser]riwakawd[/eluser]
I have got it all working with custom library called request. Which also built in xss_clean. All works perfect now.

Code:
&lt;?php

class Step_3 extends CI_Controller {
private $error = array();

public function index() {

  $this->lang->load('install', 'english');

  $data['title'] = 'Configuration';

  $data['base'] = base_url();

  if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {

   $this->load->model('model_install');

   $this->model_install->database($this->request->post);
  
   redirect(site_url('/'));

  }

   $data['entry_username'] = "Username";
   $data['entry_password'] = "Password";
   $data['entry_email'] = "Email";

   $data['button_continue'] = "Continue";
   $data['button_back'] = "Back";

   if (isset($this->error['warning'])) {
    $data['error_warning'] = $this->error['warning'];
   } else {
    $data['error_warning'] = '';
   }

   if (isset($this->error['email'])) {
    $data['error_email'] = $this->error['email'];
   } else {
    $data['error_email'] = '';
   }

   if (isset($this->error['username'])) {
    $data['error_username'] = $this->error['username'];
   } else {
    $data['error_username'] = '';
   }

   if (isset($this->error['password'])) {
    $data['error_password'] = $this->error['password'];
   } else {
    $data['error_password'] = '';
   }  

   $data['action'] = site_url('install/step_3');

   if (isset($this->request->post['username'])) {
    $data['username'] = $this->request->post['username'];
   } else {
    $data['username'] = 'admin';
   }

   if (isset($this->request->post['password'])) {
    $data['password'] = $this->request->post['password'];
   } else {
    $password = $data['password'] = '';
   }

   if (isset($this->request->post['email'])) {
    $data['email'] = $this->request->post['email'];
   } else {
    $data['email'] = '';
   }  

   $data['back'] = site_url('/');

   $data['header'] = $this->load->view('common/header', $data, true);
   $data['footer'] = $this->load->view('common/footer', null, true);

   $this->load->view('install/step_3', $data);
  
}

private function validate() {
  if (!$this->request->post['username']) {
   $this->error['username'] = $this->lang->line('error_username');
  }

  if (!$this->request->post['password']) {
   $this->error['password'] = $this->lang->line('error_password');
  }

  if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
   $this->error['email'] = $this->lang->line('error_email');
  }

  return !$this->error;
}
}
#4

[eluser]CroNiX[/eluser]
If you used the validation library properly you would probably only need about 1/2 the code you are currently using and won't keep having these problems.
#5

[eluser]Tim Brownlaw[/eluser]
I'm not sure why you are not using the Validation Library...

I'd suggest that it'd be a really good idea to give this a really good read...
http://ellislab.com/codeigniter/user-gui...ation.html

You've missed one tiny piece of the puzzle, given up and re-invented the wheel!
Did you at least try what I suggested in my previous post???????





Theme © iAndrew 2016 - Forum software by © MyBB