Welcome Guest, Not a member yet? Register   Sign In
Validation doesn't work
#1

[eluser]dlange[/eluser]
Hello,

I have a real strange issue, my code is working fine on my local machine and on my php5 server online. But on the client server (where I had to load the php5-module via cgi) the validation class doesn't work). It does check the fieldcontents but when everything is fine it just cleans the post and loads the form again (this is logical if there are no postdata to check the validator will response with false) but why does the validation class clean the postarray? And why does this only happen on this one server?

Would really appreciate your help,
Daniel
#2

[eluser]pistolPete[/eluser]
Please post the controller code, maybe there is some issue.

Which CI version are you using? Do you use the validation class or the form validation class?
Did you extend the core validation class?
#3

[eluser]dlange[/eluser]
Hi,

I'm using the 1.7 version but also tested it with the 1.7.1 version which doesn't help either ... I use the form_validation class.

These are the relevant functions in the controller:
Code:
function addUser(){
        $this->auth->check(1);
        $usergroup = $this->auth->getUsergroup();
        $data['template_path'] = $this->config->item('template_path');
        
        /* Rules */
        $this->form_validation->set_rules('anrede', 'Anrede', 'required');
        $this->form_validation->set_rules('firstname', 'Vorname', 'required');
        $this->form_validation->set_rules('name', 'Nachname', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('phone', 'Telefon', 'required');
        $this->form_validation->set_rules('admin', 'Admin', 'required|exact_length[1]|is_natural');
        $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|callback__username_check');
    
        /* Load Form */            
        if ($this->form_validation->run() == FALSE):
            $output['content'] = $this->parser->parse('user/adduser.php', $data, TRUE);
            $this->load->view('template.php', $output);
        else:
            /* Save Form */
            /* ... */
            /* ... */
            /* Redirect to Userlist */
            redirect('user/listUsers');        
        endif;

    }
    function _username_check($str)
    {
        $users = $this->db->query('SELECT * FROM users WHERE username='.$this->db->escape($str));
        $count = $users->num_rows();
        if ($count > 0):
            $this->form_validation->set_message('_username_check', 'Username is not available');
            return FALSE;
        else:
            return TRUE;
        endif;
    }
#4

[eluser]dlange[/eluser]
Well I got closer to the problem now. The problem is the email field. Even if I remove the rules for the email field, the form will only work if I leave the emailfield empty. When I fill in something into emailfield the form doesn't work anymore. And I'm sure now that the hole post is getting a reset when I fill in something into the emailfield. Does anybody know what this could be?

Update: I played around a little bit and found out that as long as there are any missing information in the form (means as long the validator doesn't accept the hole post) the postfunction works and get's through to the controller which outputs the errormessages and repopulates the form. But when I filled in everything (including the emailfield which causes the error) the post does not even come through to the controller. It just reloads the page and shows an empty form again.
#5

[eluser]pistolPete[/eluser]
That's very strange.
Did you extend any core class? Do you use any hooks? How do the server configurations differ (apart from CGI)?
You could try a fresh CI installation with only one controller as a testcase.
Is the parser somehow involved? (just guessing...)
#6

[eluser]dlange[/eluser]
Yeah it really is Sad I didn't extend or change anything in any core class, I only use my own controllers, views and 2 own libraries. How the server configuration differs is difficult to say, because it is a managed server. I only know that it runs an Apache 2 with PHP4 (which I changed to PHP5 via CGI). The strangest thing is, that this really only happens if the email field is involved, have several other forms and those work perfectly (with form_validation). The parser is used in allmost every function (even in the other forms which works) so I can't imagine that this could be the problem. I don't know ... in the worst case I have to validate manual on this server in this function ... but it would be much better if everything would work the same way on every server Wink

I really have no idea what it otherwise could be (your geuessings were good!) ...
#7

[eluser]TheFuzzy0ne[/eluser]
Please can I see your view?
#8

[eluser]dlange[/eluser]
Here you go:
Code:
<?php echo form_open('user/addUser', array('name' => 'form')); ?>
    <div class="big_sepeartor">&nbsp;</div>
    &lt;?php echo validation_errors(); ?&gt;
    <div class="headline">Persönliche Daten</div>
    <div class="form">
        <div class="col1">
            <div class="row"><span>Anrede*:</span><div class="radio"><label>Herr</label>&lt;input tabindex="1" type="radio" name="anrede" value="Herr" &lt;?php echo set_radio('anrede', 'Herr', true); ?&gt; /&gt;&lt;/label></div><div class="radio"><label>Frau</label>&lt;input tabindex="2" type="radio" name="anrede" value="Frau" &lt;?php echo set_radio('anrede', 'Frau'); ?&gt; /&gt;&lt;/div></div>
            <div class="row"><span>Vorname*:</span>&lt;input tabindex="3" type="text" class="text" name="firstname" value="&lt;?php echo set_value('firstname'); ?&gt;" /&gt;&lt;/div>
            <div class="row"><span>Firma:</span>&lt;input tabindex="5" type="text" class="text" name="company" value="&lt;?php echo set_value('company'); ?&gt;" /&gt;&lt;/div>
            <div class="row"><span>Email*:</span>&lt;input tabindex="6" type="text" class="text" name="email2" value="&lt;?php echo set_value('email'); ?&gt;" /&gt;&lt;/div>
            <div class="row"><span>Telefon*:</span>&lt;input tabindex="7" type="text" class="text" name="phone" value="&lt;?php echo set_value('phone'); ?&gt;" /&gt;&lt;/div>
        </div>
        <div class="col2">
            <div class="row nobg">&nbsp;</div>
            <div class="row"><span>Name*:</span>&lt;input tabindex="4" type="text" class="text" name="name" value="&lt;?php echo set_value('name'); ?&gt;" /&gt;&lt;/div>
            <div class="row nobg">&nbsp;</div>
            <div class="row nobg">&nbsp;</div>
            <div class="row"><span>Fax:</span>&lt;input tabindex="8" type="text" class="text" name="fax" value="&lt;?php echo set_value('fax'); ?&gt;" /&gt;&lt;/div>
        </div>
    </div>
    <div class="headline">Zugangsdaten</div>
    <div class="form">
        <div class="col1">
            <div class="row"><span>Benutzername*:</span>&lt;input tabindex="9" type="text" class="text smalltext" name="username" value="&lt;?php echo set_value('username'); ?&gt;" /&gt;&lt;/div>
            <div class="row"><span>Admin*:</span><div class="radio"><label>ja</label>&lt;input tabindex="10" type="radio" name="admin" value="1" &lt;?php echo set_radio('admin', '1'); ?&gt; /&gt;&lt;/label></div><div class="radio"><label>nein</label>&lt;input tabindex="11" type="radio" name="admin" value="0" &lt;?php echo set_radio('admin', '0', TRUE); ?&gt; /&gt;&lt;/div></div>
        </div>
    </div>
    <div class="small_seperator">&nbsp;</div>
    <div class="control">
        <div class="left"><a href="&lt;?php echo site_url('user/listUsers'); ?&gt;"><img src="{template_path}/img/bt_back.gif" /></a></div>
        <div class="right"><a tabindex="12"><img src="{template_path}/img/bt_go.gif" /></a><span class="blue">User anlegen und Zugangsdaten verschicken:</span></div>
    </div>
&lt;/form&gt;
#9

[eluser]TheFuzzy0ne[/eluser]
The name of your email input is "email2" and the validation library is looking for "email".
#10

[eluser]dlange[/eluser]
Oh sorry, I was only teesting ... it was "email" before and isn't either working with "email" or "email2"




Theme © iAndrew 2016 - Forum software by © MyBB