Welcome Guest, Not a member yet? Register   Sign In
Captcha - After Failure
#1

[eluser]Canimus[/eluser]
Hi,

I need some assistance or comments about how to handle the display of the image for the CAPTCHA if the user fail in the input of the word displayed.
The problem is that the index() function which displays the form, is the one that generates the captcha image, and its passed via the $data array to the view.

The problem is that the register function does not have any reference to that value, therefore I have to put the entire tag of the image in a hidden field in the form, so I can retrieve it again after the first attemp.

Below the code.

I have done a User Controller with the following code for the display of my login form:

Code:
private $locale;

    function User() {
        parent::Controller();

        // Initialization for the user preferred language
        $this->locale = 'english';

        // This helper is the gatekeeper for the application
        $this->load->model('User_model', 'gatekeeper');
    }

    function index() {


        // Loading of external libraries
        $this->load->helper(array('form', 'url', 'language'));
        $this->lang->load('labels', $this->locale);
        $this->lang->load('form_validation', $this->locale);

        // Routine to collect the validation image
        $cap = $this->gatekeeper->throw_captcha();

        // Posting information for the view
        $data['captcha_image'] = $cap['image'];

        $this->load->view('user/login', $data);
    }

After this, my Controller has another function that validate successfully the form using the validation rules in the form_validation.php

Code:
function register() {

        $this->load->helper(array('form', 'url', 'language'));
        $this->lang->load('labels', $this->locale);
        $this->lang->load('form_validation', $this->locale);
        $this->load->library('form_validation');

        log_message('info', 'Current Locale is: ' . $this->locale);

        if ($this->form_validation->run() == FALSE) {
            log_message('info', 'Form validation: FAIL');
            log_message('info', 'Reloaded:' . $this->input->post('captcha_reload'));
            $data['captcha_image'] = $this->input->post('captcha_reload');
            $this->load->view('user/login', $data);
        }
        else {
            log_message('info', 'Form validation: PASS');
            $this->gatekeeper->register_user();
            $this->load->view('user/home');
        }
    }


Any ideas on how to retrieve again the entire image file? is preferrable to put it in the user session data? rather than in hidden value in the view?

Example of the view show below:
Code:
<label for="&lt;?php echo CAPTCHA;?&gt;">&lt;?php echo lang('label_captcha');?&gt;:</label>
            &lt;?php echo form_error('captcha'); ?&gt;
            &lt;input type="text" id="captcha" name="captcha" size="50" value="" tabindex="7"&gt;
            <p class="tips">&lt;?php echo lang('label_captcha_tip'); ?&gt;</p>
            &lt;?php echo $captcha_image ?&gt;

            &lt;input type="hidden" id="captcha_reload" name="captcha_reload" value='&lt;?php echo $captcha_image ?&gt;'&gt;
            <br>

Thanks for your comments and help.
Regards,
C#12




Theme © iAndrew 2016 - Forum software by © MyBB