Welcome Guest, Not a member yet? Register   Sign In
Form not working
#1

[eluser]HooJee[/eluser]
Hi Guys

I am trying to valiate my form using the form_validation controller but everytime I submit my form nothing happens. Code below:

// HTML
Code:
<?php echo validation_errors(); ?>
<form id="contactForm">
    <div class="padding"> Your Name: </div>
    &lt;input type="text" name="name" id="name" size="35"/&gt; <br />
    <div class="padding"> Your Email: </div>
    &lt;input type="text" name="email" id="email" size="35"/&gt; <br />
    <div class="padding"> Comments: </div>
    &lt;textarea id="comments" name="comments" &gt;&lt;/textarea> <br />
    &lt;input type="submit" id="submit" value="Submit"/&gt;
    <span></span>
&lt;/form&gt;

// Controller
Code:
function contact() {
    $this->load->helper(array('form', 'url'));
    
    $this->load->library('form_validation');
        
    $this->form_validation->set_rules('name', 'Name|min_length[1]', 'required');
    $this->form_validation->set_rules('email', 'Email|valid_email', 'required');
    $this->form_validation->set_rules('comments', 'Comments', 'required|min_length[5]');
        
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('ajax/contact');
    } else {
        $this->load->view('formsuccess');
    }
}
#2

[eluser]David Johansson[/eluser]
You have som errors... I don't know if I found all of them, but here is you code with some improvements:

// HTML
Code:
&lt;?php echo validation_errors(); ?&gt;
&lt;form action="/*change tho the path to your controller*/" method="post" id="contactForm"&gt;
    <div class="padding"> Your Name: </div>
    &lt;input type="text" name="name" id="name" size="35"/&gt; <br />
    <div class="padding"> Your Email: </div>
    &lt;input type="text" name="email" id="email" size="35"/&gt; <br />
    <div class="padding"> Comments: </div>
    &lt;textarea id="comments" name="comments" &gt;&lt;/textarea> <br />
    &lt;input type="submit" id="submit" value="Submit"/&gt;
    <span></span>
&lt;/form&gt;

// Controller
Code:
function contact() {
    $this->load->helper(array('form', 'url'));
    
    $this->load->library('form_validation');
        
    $this->form_validation->set_rules('name', 'Name', 'required|min_length[1]');
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
    $this->form_validation->set_rules('comments', 'Comments', 'required|min_length[5]');
        
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('ajax/contact');
    } else {
        $this->load->view('formsuccess');
    }
}
#3

[eluser]InsiteFX[/eluser]
Please read the CodeIgniter Users Guide form helper

You are missing methos post action in your form code.

Enjoy
InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB