Welcome Guest, Not a member yet? Register   Sign In
Validation in autoload PHP 4 (Fix suggested)
#16

[eluser]karloff[/eluser]
controller
Code:
function comments ()
    {
        
    $data['title'] = $this->uri->segment(3);
    $this->db->where('url_title', $this->uri->segment(3));
        $data['entriesquery'] = $this->db->get('entries');


        $this->db->where('entry_id', $this->uri->segment(3));
        $data['commentquery'] = $this->db->get('comments');

        
    $rules['author'] = "trim|required";
        $rules['email'] = "trim|required|valid_email|max_length[50]";
        $rules['body'] = "trim|required|htmlentities|max_length[2000]";
        
    $this->validation->set_rules($rules);

        $fields['author']    = 'Author';
        $fields['body']        = 'body';
        $fields['email']    = 'Email Address';

    $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<p class="error">', '</p>');

        if ($this->validation->run() == FALSE) {
        $this->load->vars(array(
            'data' => $data,
         ));
        $this->load->view('comment_view', $data);
            
        } else {
                      
        $this->db->insert('comments', $_POST);
        redirect('blog/comments/'.$_POST['entry_id']);
        }



    }
function comments_insert ()
    {
    $rules['author'] = "trim|required";
        $rules['email'] = "trim|required|valid_email|max_length[50]";
        $rules['body'] = "trim|required|htmlentities|max_length[2000]";
        
    $this->validation->set_rules($rules);

        $fields['author']    = 'Author';
        $fields['body']        = 'body';
        $fields['email']    = 'Email Address';

    $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<p class="error">', '</p>');

        if ($this->validation->run() == FALSE) {
        
        $this->load->view('comment_view', $data);
            
        } else {

                          
            $this->db->insert('comments', $_POST);
        
        redirect('blog/comments/'.$_POST['entry_id']);
        }
    }
view
Code:
&lt;?=form_open('blog/comments/' .$this->uri->segment(3));?&gt;
    
&lt;?php     echo $this->validation->error_string; ?&gt;
    
    <fieldset>

        <ul>
            <li><label>Comments (required):</label></li>
            
            <li>&lt;? $data = array(
                                'name'    => 'body',
            
                                );
                                echo form_textarea($data);
                             ?&gt;</li>
            <li><label>Name (required):</label></li>
            <li>&lt;?=form_input('author', $row->author); ?&gt;</li>
            <li><label>URL:</label></li>
            <li>&lt;input type="text" value="http://" name="url" /&gt;&lt;/li>            

            <li><label>Email (not published, required):</label></li>
            <li>&lt;input type="text" value="" name="email" /&gt;&lt;/li>            

            <li>&lt;input type="submit" value="Submit Comment" class="submit" /&gt;&lt;/li>
                
        
        </ul>
        &lt;?=form_hidden('entry_id', $this->uri->segment(3));?&gt;
        
    </fieldset>
    &lt;/form&gt;


Messages In This Thread
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-16-2008, 08:05 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 09:59 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 01-17-2008, 10:01 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:10 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 03:38 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:19 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-15-2008, 04:25 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 01:51 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:20 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:26 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-16-2008, 02:55 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 01:37 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:41 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:43 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:44 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 02:59 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-21-2008, 03:36 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 07-22-2008, 04:06 PM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 08-30-2008, 05:42 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:50 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 08:54 AM
Validation in autoload PHP 4 (Fix suggested) - by El Forum - 09-02-2008, 09:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB