Welcome Guest, Not a member yet? Register   Sign In
Form_Validation not recognizing erros? HELP! :-)
#1

[eluser]datdesignguy[/eluser]
Hi All,

I ended up cutting out hmvc for this app, as I realized the code wasn't going to need to be portable. So I'm using a straight CI 1.7.1 install.

I have an account creation page with the following fields: firstName,lastName,email,password,password_conf, and timezone.

The rules I have set for validation are as follows:

Code:
$this->load->library('form_validation','','validation');
            $this->validation->set_error_delimiters('<div class="error">','</div>');
            $this->validation->set_rules('firstName','First Name','trim|required');
            $this->validation->set_rules('lastName','Last Name','trim|required');
            $this->validation->set_rules('email','E-Mail Adress','strtolower|trim|required|valid_email|callback_checkexists');
            $this->validation->set_rules('password','trim|required|min_length[6]|max_length[32]');
            $this->validation->set_rules('password_conf','trim|required|matches[password]');
            $this->validation->set_rules('timezone','required');

This is what my view file looks like:

Code:
<%= form_open('account/create'); %>
<fieldset>
<legend>Create Your Account: </legend>
<%= form_error('firstName'); %>
<div class="form_row">
    <label for="firstName">First Name: </label>
    &lt;input type="text" id="firstName" name="firstName" value="&lt;%= set_value('firstName'); %>" />
</div>
<%= form_error('lastName'); %>
<div class="form_row">
    <label for="lastName">Last Name: </label>
    &lt;input type="text" id="lastName" name="lastName" value="&lt;%= set_value('lastName'); %>" />
</div>
<%= form_error('email'); %>
<div class="form_row">
    <label for="email">E-mail Address: </label>
    &lt;input type="text" id="email" name="email" value="&lt;%= set_value('email'); %>" />
</div>
<%= form_error('password'); %>
<div class="form_row">
    <label for="password">Password: </label>
    &lt;input type="password" id="password" name="password" value="" /&gt;
</div>
<%= form_error('password_conf'); %>
<div class="form_row">
    <label for="password_conf">Confirm Password: </label>
    &lt;input type="password" id="password_conf" name="password_conf" value="" /&gt;
</div>
<%= form_error('timezone'); %>
<div class="form_row">
    <strong>Please select Your Time Zone:</strong><br/>
    <select name="timezone">
    <% $tzs = timezones(); %>
    <% foreach($tzs as $k => $v):%>
      <option <%= set_select('timezone',$k);%> value="<%=$k%>"><%=$this->lang->line($k);%></option>
    <% endforeach; %>
      <option value='' <%=set_select('',TRUE);%>>Please Set Your Time Zone</option>
    </select>
</div>
<div class="form_row">
    &lt;input type="submit" id="doCreate" name="doCreate" value="Create My Account!" /&gt;
</div>
</fieldset>
&lt;/form&gt;

I cannot for the life of me figure out why, when I test the form, it thinks there is nothing wrong even though I am leaving: password, password_conf, and timezone unset. Even if I leave the whole form blank, it only shows errors for the first 3 fields (firstName,lastName, and email) any idea what I'm doing wrong?

Thanks!

- Greg J
#2

[eluser]verynewtothis[/eluser]
I think you are missing the second parameter of your last 3 validation rules... just compare them with the first 2 and you will know...
#3

[eluser]verynewtothis[/eluser]
oops I guess this is allowed... sorry bad post

Quote:EDIT

I did confirm by testing your code and the reason that I gave earlier was correct...
#4

[eluser]datdesignguy[/eluser]
wow... I feel so slow. I left out the human-friendly field names, lol. geez!




Theme © iAndrew 2016 - Forum software by © MyBB