Reputation: 3749
I have a question about form validation in CodeIgniter:
<? form_open('user/check_login' ?>
<fieldset id="login_fields">
<label for="login">Login</label>
<input name="login" type="text" class="textfield" id="login" />
<label for="password">Password</label>
<input name="password" type="password" class="textfield" id="password" />
<input type="submit" name="Submit" value="Login" />
</fieldset>
</form>
As the you can see above, the form is submitted to check_login method in user controller.
After a certain number of unsuccessful login attempts, I would include another input field (captcha) in the form. For example
<? if ($attempts > 3) { ?>
<label for="captcha">captcha</label>
<input name="captcha" type="text" class="textfield" id="captcha" />
<? } ?>
But the problem is that when the extra field is added, and the form is submitted then, how the check_login method will know that this time captcha field was added in the form, and that can not be left blank.
Thanks.
Upvotes: 0
Views: 140
Reputation: 1184
isset( $_POST['captcha'] )
or
$this->input->post('captcha') not equals to FALSE
if any of this conditions are meet, the add the rule to the form_validation.
Upvotes: 0
Reputation: 82028
You're either need to use the CI session library or the PHP $_SESSION array. Personally, I would use flash_data in the session lib.
$this->load->library('session');
$attempts = $this->session->flashdata('fails');
if(!is_numeric($attempts)) $attempts = 0;
else $attempts++;
$this->session->set_flashdata('fails', $attempts);
At that point, you can just pass $attempts to your view and you should be good.
Upvotes: 1