Welcome Guest, Not a member yet? Register   Sign In
Form validation[SOLved]
#1

[eluser]Ivar89[/eluser]
i tried so much...read the user_guide and its still not working...
It IS sending my message when all fields are filled
and it does NOt sent when required fields are not filled which is good
I just DON'T get error messages...:S
controller:
Code:
if ($this->form_validation->run('contact') == TRUE)
            {
               //sending email here(but my post is to long and thuis is not relevant for the problem since this works.
            }
            else
            {
                redirect('contact');
            }
    }
Code:
<?php
$config = array('contact' => array(array('field' => 'bedrijfsnaam',
                                         'label' => 'company',
                                         'rules' => 'required|callback_check_form'
                                        ),    
                                    array('field' => 'Naame',
                                        'label' => 'Name',
                                        'rules' => 'required'
                                         ),
                                    array('field' => 'adres',
                                        'label' => 'adress',
                                        'rules' => 'required'
                                         ),
                                    array('field' => 'postcode',
                                        'label' => 'postcode',
                                        'rules' => 'required'
                                         ),
                                    array('field' => 'Plaats',
                                        'label' => 'city',
                                        'rules' => 'required'
                                         ),
                                    array('field' => 'Email',
                                        'label' => 'email',
                                        'rules' => 'required'
                                         ),
                                    array('field' => 'bericht',
                                        'label' => 'message',
                                        'rules' => 'required'
                                         ),
                                    )
                );
?>
controller callback_check_form
Code:
function check_form()
    {    
         if($this->input->post('company'))
            {
            $data = array('company' => true, 'name' => true, 'adress' => true, 'postcode' =>  true, 'city' => true, 'email' => true, 'message' => true);

            if($data)return true;
            }
            $this->form_validation->set_message('required',  'You did not fill out all the required fields ( * ).');
            return false;
    }
View:
Code:
<?php if ($id == 'contact'): ?>
    <?php echo form_open('thanks'); ?>
        <table>
            <tr>
                <td>
                    <label id="company">Bedrijfsnaam*:</label>
                </td>
                <td>
                    &lt;input type="text" name="company" id="company" value="&lt;?php set_value('company') ?&gt;" style="width:153px"&gt;
     &lt;?php echo form_error('company')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="Name">Naam*:</label>
                </td>
                <td>
                    &lt;input type="text" name="name" id="name" value="&lt;?php set_value('name') ?&gt;" style="width:153px"&gt;
                    &lt;?php echo form_error('name')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="adress">Adres*:</label>
                </td>
                <td>
                    &lt;input type="text" name="adress" id="adress"value="&lt;?php set_value('adress') ?&gt;"  style="width:153px"&gt;
                    &lt;?php echo form_error('adress')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="postcode">Postcode</label> & <label id="city">Plaats*:</label>
                </td>
                <td>
                    &lt;input type="text" name="postcode" id="postcode" value="&lt;?php set_value('postcode') ?&gt;" style="width:50px"&gt;
                    &lt;?php echo form_error('postcode')?&gt;
                    &lt;input type="text" name="city" id="city" value="&lt;?php set_value('city') ?&gt;" style="width:98px"&gt;
                    &lt;?php echo form_error('city')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="email">Email*:</label>
                </td>
                <td>
                    &lt;input type="text" name="email" id="email" value="&lt;?php set_value('email') ?&gt;" style="width:153px"&gt;
                    &lt;?php echo form_error('email')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="phone">Telefoon:</label>
                </td>
                <td>
                    &lt;input type="text" name="phone" id="phone" style="width:153px"&gt;
                    &lt;?php echo form_error('phone')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="fax">Fax:</label>
                </td>
                <td>
                    &lt;input type="text" name="fax" id="fax" style="width:153px"&gt;
                    &lt;?php echo form_error('fax')?&gt;
                </td>
            </tr>
            <tr>
                <td>
                    <label id="message">Bericht*:</label>
                </td>
            </tr>
My post is to long but I closed everything
#2

[eluser]tomcode[/eluser]
Looks like Your form_validation.php is not correct :

Code:
array('field' => 'company',               // the field must match field name in the form
          'label' => 'Bedrijfsnaam',       // the label is used in the error message text
          'rules' => 'required|callback_check_form'
),

Code:
<td>
    <label for="company">Bedrijfsnaam*:</label>
</td>
<td>
     &lt;input type="text" name="company" id="company" value="&lt;?php set_value('company') ?&gt;" style="width:153px"&gt;
     &lt;?php echo form_error('company')?&gt;
</td>
#3

[eluser]Ivar89[/eluser]
thanks I fixed that but still not working...
#4

[eluser]WanWizard[/eluser]
When the validation is not correct you do a redirect, which is a new page request. Which means everything is lost.
Instead of the redirect you should reload your view.
#5

[eluser]Ivar89[/eluser]
Thanks, that fixed it indeed^^




Theme © iAndrew 2016 - Forum software by © MyBB