Welcome Guest, Not a member yet? Register   Sign In
Fckeditor Form Validation
#1

[eluser]macleodjb[/eluser]
I've been having periodic problems with Fckeditor when it comes to validation. It will assume that the editor field is empty when in fact it has text inside. Thus preventing the form from being submitted.

This is what i have in my controller.
Code:
$this->load->library('fckeditor',array('instanceName' => 'resume'));
$this->fckeditor->BasePath = base_url().'system/plugins/fckeditor/';
$this->fckeditor->ToolbarSet = 'Default';
$this->fckeditor->Height = 400;
$this->fckeditor->Width = 700;
$this->fckeditor->Value = $resume_value;
$data['resume_box'] = $this->fckeditor->CreateHtml();

and this is what i have inside my view
Code:
<?php echo $resume_box; ?>

Anyone else have the same problem?
#2

[eluser]pistolPete[/eluser]
I don't know how the FCKeditor library works, but I assume that the generated textarea's name is resume in that case.

So you need to set the following validation rule:
Code:
$this->form_validation->set_rules('resume', 'Resume', 'required');

Please verify which html is generated and how your validiation rules are setup!
#3

[eluser]macleodjb[/eluser]
My validation rules are set up like this.

Code:
$rules['resume'] = "required";

        $this->validation->set_rules($rules);

And it keep telling me that the resume field is required even though it has content
#4

[eluser]pistolPete[/eluser]
Which html is generated? Is the textareas name really resume?
Why are you using the deprecated validation library instead of the form validation library?

Check if the contents are submitted via POST:
Code:
echo '<pre>'.print_r($_POST, TRUE).'</pre>';
#5

[eluser]macleodjb[/eluser]
how is the validation library deprecated? i took it right from the docs.

http://ellislab.com/codeigniter/user-gui...ation.html

but anyway, i inserted the snippet you provided and it is in fact posting the contents but it doesn't appear to be assigned to "resume". this is how the array starts and then prints the content.

Code:
Array
(
    [Array] =>
#6

[eluser]pistolPete[/eluser]
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
Quote:Note: As of CodeIgniter 1.7.0, this Form Validation class supercedes the old Validation class, which is now deprecated.

Try using just a plain html textarea (without the WYSIWYG) and check if that passes your validation.
If that isn't working, you need to post more code (full controller and view).
#7

[eluser]macleodjb[/eluser]
well answer me this before i do that. if i use a textarea without wysiwyg, is there a way to keep my text in a neat fashion instead of mashed together. I mean I want to see the link breaks and all that in the text area, i'm sure there's a way but i don't know how to do it.
#8

[eluser]pistolPete[/eluser]
The suggestion to try just a plain textarea was just for debugging purposes.

In general: There are some other WYSIWYG editors around, e.g. tinyMCE which I prefer.
But FCKeditor should work, just don't use that library which probably causes that problem and directly integrate it into you view like its user guide advises.
#9

[eluser]macleodjb[/eluser]
I switched to a text area and discovered that it is in fact updating the resume in the database with the exception of the actual resume. It is modifying the date_modified field but not the resume_text field. I switched to $_POST instead of using codeigniter and it does the same thing.

here's my function.
Code:
function update_resume($id) {
        $resume_post = $_POST['resume_body'];
        $resumetxt = htmlspecialchars(strip_tags(trim($resume_post),'<strong><i><br><br />'));
        $update_resume = $this->db->query("UPDATE `user_resume` SET "
        . "`resume_text` = '".$resumetxt."', "
        . "`date_modified` = NOW() WHERE (`user_id` = '$id')");
        $r_updated = $this->db->affected_rows($update_resume);
        if($r_updated > 0) {
        return true;
        } else {
        return false;
        }
    }

and this is my current html
Code:
&lt;textarea cols="70" rows="20" name="resume_body"&gt;&lt;?php echo $resume_info; ?&gt;&lt;/textarea&gt;

and this is in my controller.
Code:
function resume() {
        if(!isset($_SESSION['uid'])){
        $this->session->set_flashdata('message','You must be logged in to edit your resume');
        redirect('login/login');
        }
        if($_SESSION['user_type'] == '1'){
        $this->session->set_flashdata('message','We\'re Sorry you do not have access to this section');
        redirect('home');
        }

        $this->load->model('Edit_model');
        $this->load->model('Main_model');
        $this->load->library('form_validation');
        $user_id = $_SESSION['uid'];
        $resume_info = $this->Main_model->get_resume($user_id);
        
        if($this->input->post('resume')){
        $resume_value = $this->input->post('resume_body');
        } else {
        $resume_value = $resume_info['resume_text'];
        }
        
        
        $this->load->library('fckeditor',array('instanceName' => 'resume_body'));
        $this->fckeditor->BasePath = base_url().'system/plugins/fckeditor/';
        $this->fckeditor->ToolbarSet = 'Basic';
        $this->fckeditor->Height = 400;
        $this->fckeditor->Width = 700;
        $this->fckeditor->Value = $resume_info['resume_text'];//$resume_value;
        
        
        $data['resume_box'] = $this->fckeditor->CreateHtml();            
        
        $this->form_validation->set_rules('resume_body', 'resume_body', 'htmlspecialchars|trim|required');
    
        $data['resume_info'] = $resume_info['resume_text'];
        $data['page_title'] = "";
        $data['page_desc'] = "";
        $data['page_keywords'] = "";
        $data['industry'] = $this->Main_model->get_industry();
            
        if ($this->form_validation->run() == FALSE){
            $this->load->view('edit/edit_resume', $data);
        } else {
            $resume = $this->input->post('resume_body');
            if(empty($resume)){
            echo "Resume was empty";
            } else {
            
            if($this->Edit_model->update_resume($_SESSION['uid'])){
            $this->session->set_flashdata('message','Your resume was sucessfully updated!');
            redirect('dashboard');
            } else {
            $this->session->set_flashdata('message','There was an internal error, please contact support');
            redirect('dashboard');
            }
            }
        }
        
    }// end of function




Theme © iAndrew 2016 - Forum software by © MyBB