• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Tooltip not show when form error codeigniter

#1
When I submit my form if there is a error on title i am trying to be able to trigger the tooltip.

Small part of the view below.

PHP Code:
<div class="form-group">
<
label class="title_label" for="title">Title: </label>
<
span class="title_input"><?php echo form_input('title'$title, array('id' => 'title''class' => 'form-control'));?></span>
</div>

<script type="text/javascript">
<?php if ($error_title) {?>
$('#title').tooltip({
    title: "<?php echo $error_title;?>",
    animated: 'fade',
    placement: 'right',
    trigger: 'click'
}); 
<?php }?>
</script> 


How ever does not seem to pick up the if (form_error('title')) {} on the controller. I have autoload the form_helper.

I can see the validation messages when I use echo validation_error();

Question how can I make sure when there is a form_error it will run the tooltip.


PHP Code:
<?php

class Ask extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('parsedown');
        $this->load->library('form_validation');
        $this->parsedown->setLiteralBreaks(true);
    }

    public function index() {
        if (form_error('title')) {
            $this->data['error_title'] = form_error('title');
        } else {
            $this->data['error_title'] = '';
        }

        if (form_error('message')) {
            $this->data['error_message'] = form_error('message');
        } else {
            $this->data['error_message'] = '';
        }

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

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

        $this->form_validation->set_rules('title''title''trim|required|min_length[15]|max_length[100]');
        $this->form_validation->set_rules('message''message''trim|required|min_length[15]');

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

            $this->data['children'] = array(
                'common/header',
                'common/navbar',
                'common/footer'
            );

            $this->load->render('question/ask'$this->data);

        } else {
            
        
}
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
u can use form_error('title') which shows error message. but first u need to add rule in form_validation->set_rule(..); to be able to see from_error() message. 

u can also add delimiters  $this->form_validation->set_error_delimiters('<div class="input-error">', '</div>');
and then select by $('.input-error')

to check if there is error u can use <?php if (from_error('title') != '') {?>
Reply

#3
(03-10-2017, 08:33 AM)neuron Wrote: u can use form_error('title') which shows error message. but first u need to add rule in form_validation->set_rule(..); to be able to see from_error() message. 

u can also add delimiters  $this->form_validation->set_error_delimiters('<div class="input-error">', '</div>');
and then select by $('.input-error')

to check if there is error u can use <?php if (from_error('title') != '') {?>

Did not help what I am wanting to do with tooltip
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#4
I have now solved it

On script I have had to use .tooltip('show') like


PHP Code:
$(function () {
 
   $('input[name=title]').tooltip({
 
       placement"right",
 
       container:'body',
 
       title'<?php echo $error_title;?>',
 
       /*trigger: "hover"*/
 
   }).tooltip('show');
}); 


And on controller

Change the form error around


PHP Code:
public function index() {
    
        
$this->data['error_title'] = '';
    
        if (
$this->input->post('title')) {
            
$this->data['title'] = $this->input->post('title');
        } else {
            
$this->data['title'] = '';
        }

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

        
$this->form_validation->set_rules('title''title''trim|required|min_length[15]|max_length[100]');
        
$this->form_validation->set_rules('message''message''trim|required|min_length[15]');

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

            
$this->data['error_title'] = form_error('title'' '' ');

            
$this->data['children'] = array(
                
'common/header',
                
'common/navbar',
                
'common/footer'
            
);

            
$this->load->render('question/ask'$this->data);

        } else {
            
        }
    } 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.