Welcome Guest, Not a member yet? Register   Sign In
form validation question
#1

[eluser]Unknown[/eluser]
Hi!

I'm having problems validating a form... And I don't know why. I don't get any value from set_values() and even if I remove all the rules I still get FALSE when I'm trying to validate it...

Here is the form:
Code:
<?php echo validation_errors(); ?>

    <?php echo form_open('contact'); ?>
    <table>
        <tr valign="top">
            <td>
    <fieldset id="perso">
        <legend>Informations Personelles</legend>
        <label for="txtNom">Votre nom:</label>&lt;input type="text" id="txtNom" value="&lt;?=set_value('txtNom'); ?&gt;" /&gt;
        <label for="txtCourriel">Votre adresse courriel:</label>&lt;input type="text" id="txtCourriel" value="&lt;?=set_value('txtCourriel'); ?&gt;" /&gt;&lt;br /><br />
            <p align="center">&lt;input type="submit" value="Envoyer" id="button" /&gt;&lt;/p>
            </fieldset>
            </td>
            <td>
    <fieldset id="message">
        <legend>Votre message</legend>
        &lt;textarea id="txtMessage"&gt;&lt;?=set_value('txtMessage'); ?&gt;&lt;/textarea&gt;
    </fieldset>
            </td>
        </tr>
    </table>
    &lt;/form&gt;

and here is the controlleR:
Code:
&lt;?php
class Contact extends Controller {

    function index()
    {
        $helpers = array('html', 'url', 'text', 'form');
        $this->load->helper($helpers);
        $data['infos'] = $this->db->get('contact');
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('txtNom', 'Votre nom', 'required');
        $this->form_validation->set_rules('txtCourriel', 'Votre adresse courriel', 'required|valid_email');
        $this->form_validation->set_rules('txtMessage', 'Votre message', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('contactview', $data);
        }
        else
        {
            $this->load->view('contact_successview', $data);
        }
    }
}
?&gt;

contactview is actually the form's view.

Thanks a lot!
#2

[eluser]LuckyFella73[/eluser]
I'm not shure if this was the problem but
you could try to set the name of your form elements
(just set the name vakues like your id values).
I see that you only set the ids and the user guide
is talking about setting the name attribute.
#3

[eluser]Unknown[/eluser]
Oh I'm so dumb! You are so right Smile

And is there any way to translate error messages? Thanks!
#4

[eluser]LuckyFella73[/eluser]
You can add other language files besides the default english and
edit the conf.php set "language" to your desired language.
You can set up custom error messages using the form validation class
as well. Its described in here (user guide):
http://ellislab.com/codeigniter/user-gui...ation.html
Look at section "Setting error messages"




Theme © iAndrew 2016 - Forum software by © MyBB