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

[eluser]mmcglynn[/eluser]
I am trying to set up validation on a simple contact form that is created using the form helper. No validation at all occurs. Do these two things even work together?

In the below, the "good" keyword always shows, regardless of what is entered into the form, and the saved values set via set_value are never shown.

Controller
Code:
// Contact
    function contact() {
        $data['pageTitle'] = "Contact";
        $data['bodyId'] = "contact";
        
        $this->load->library('form_validation');
        
        $config_rules = array ('email' => 'required','message' => 'required');
        
        $this->form_validation->set_rules($config_rules);
        
        if ($this->form_validation->run() == FALSE) {
            echo "bad";            
            $data['include'] = "v_contact";    
            $this->load->view('v_template',$data);
            
        } else {
            echo "good";
            $data['include'] = "v_contact";        
            $this->load->view('v_template',$data);
        }
        
    }

View
Code:
echo validation_errors();
echo form_open('events/contact');

// name
echo form_label('Name', 'name');
$data = array (
        'name' => 'name',
        'id' => 'name',
        'maxlength' => '64',
        'size' => '40',
        'value' => set_value('name')
    );
echo form_input($data) . "\n<br />";

// email address
echo form_label('Email Address', 'email');
$data = array (
        'name' => 'email',
        'id' => 'email',
        'maxlength' => '64',
        'size' => '40',
        'value' => set_value('email')
    );
echo form_input($data) . "\n<br />";

// message
echo form_label('Message', 'message');
$data = array (
        'name' => 'message',
        'id' => 'message',
        'rows' => '8',
        'cols' => '35',
        'value' => set_value('message')
    );
echo form_textarea($data) . "\n<br />";

echo form_submit('mysubmit', 'Send Message');

echo form_close();


Messages In This Thread
Form Validation Using Form Helper - by El Forum - 06-13-2010, 12:51 PM
Form Validation Using Form Helper - by El Forum - 06-13-2010, 01:35 PM
Form Validation Using Form Helper - by El Forum - 06-13-2010, 01:49 PM
Form Validation Using Form Helper - by El Forum - 06-13-2010, 02:01 PM
Form Validation Using Form Helper - by El Forum - 06-13-2010, 02:14 PM
Form Validation Using Form Helper - by El Forum - 06-13-2010, 02:24 PM
Form Validation Using Form Helper - by El Forum - 06-14-2010, 02:25 AM
Form Validation Using Form Helper - by El Forum - 06-14-2010, 02:29 PM
Form Validation Using Form Helper - by El Forum - 06-15-2010, 12:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB