Welcome Guest, Not a member yet? Register   Sign In
Form_Validation - Unable to access an error message corresponding to your field name.
#1

[eluser]Jevedor[/eluser]
This is driving me nuts

I am using a custom call back and i am pretty sure I am doing it correctly as I have used this exact same function on other website and it has worked fine.

this is the relevant code

Code:
function title_check () {
        $this->db->where('news_title', $_POST['news_title']);
        $check = $this->db->get('news');
        $news = $check->row();
        
        $allowed = $this->form_functions->allowed_characters('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890&/- '."'".'"');
        $valid_chars = $this->form_functions->compare_allowed_characters($_POST['news_title'], $allowed);
        
        if (!$valid_chars) {
            $this->form_validation->set_message('title_check', 'Titles may only use spaces, letters, numbers, ampersands, forward slashes or hyphens');
            return false;
        } else if (!empty($news)) {
            $seg3 = $this->uri->segment(3);
            if (empty($seg3) || (!empty($seg3) && $news->news_id != $seg3)) {
                $this->form_validation->set_message('title_check', 'This Title has already been created');
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
Code:
function create_news() {
        
        //Check incoming variables
        $this->form_validation->set_rules('news_title', 'News Title', "required|callback_title_check");
        $this->form_validation->set_rules('category_id', 'Category', "required|integer");
        $this->form_validation->set_rules('href', "Redirect URL");
        $this->form_validation->set_rules('target', 'Target', "required");
        $this->form_validation->set_rules('news_date', 'Date');
        
        $this->form_validation->set_rules('news_content', 'News Content');
        
        $this->form_validation->set_rules('meta_description', 'Meta Description');
        $this->form_validation->set_rules('meta_keywords', 'Meta Keywords');
        
        if (($this->form_validation->run() == false || !empty($_POST['edit']))) {

            $this->template->create_template('Create News Item :: News Admin', 'news_admin/news_form', $data);
        
        } else {
            ...
        }
        
    }

why are my error messages not working?? i have gone so far as to make my custom message look like this just to test it and it still doesnt work.

Code:
function title_check () {
            $this->form_validation->set_message('title_check', 'Titles may only use spaces, letters, numbers, ampersands, forward slashes or hyphens');
            return false;
    
    }

help?
#2

[eluser]Ickes[/eluser]
Could you post your form view as well? That may help.

Thanks.
#3

[eluser]Jevedor[/eluser]
here is the relevant part of the form


<div id="newsAdmin" >

&lt;form action="/news_admin/&lt;?=$return_process?&gt;/&lt;?=!empty($news-&gt;news_id) ? $news->news_id : '' ?&gt;" method="post" id="adminForm">

Code:
<fieldset>
        
            <legend>&lt;?=ucwords(humanize($return_process))?&gt;</legend>
        
            &lt;?php
            $errors = validation_errors('<li class="error">', '</li>');
            if (!empty($errors)):
            ?&gt;
            <div id="errorContainer">
                <ul>
                    &lt;?=$errors?&gt;
                </ul>
            </div>
            &lt;?php endif; ?&gt;
        
            <label for="news_title">News Title</label>
            &lt;input name="news_title" id="news_title" value="&lt;?= set_value('news_title', !empty($news-&gt;news_title) ? $news->news_title : '' ); ?&gt;" /><br />




Theme © iAndrew 2016 - Forum software by © MyBB