Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple forms with captcha #25

Closed
formatz opened this issue Jul 3, 2013 · 6 comments
Closed

Multiple forms with captcha #25

formatz opened this issue Jul 3, 2013 · 6 comments

Comments

@formatz
Copy link

formatz commented Jul 3, 2013

Hi,

If you add multiple forms to a page and each of them contains a captcha field, only the last field is saved to session data (it overrides the actual value).

I fixed this by adding the formId value to the name of the captcha field :

    public function addCaptcha($arrData=array())
    {
        if (!isset($this->arrFields['captcha']))
        {
            $this->arrFields['captcha'] = array_merge_recursive(array
            (
                'name'      => 'captcha_'.$this->strFormId,
                'label'     => $GLOBALS['TL_LANG']['MSC']['securityQuestion'],
                'inputType' => 'captcha',
                'eval'      => array('mandatory'=>true)
            ), $arrData);
        }
    }

Thanks,
Fabien

@qzminski
Copy link
Member

qzminski commented Jul 5, 2013

Thanks for reporting this issue and fixing it!

@qzminski qzminski closed this as completed Jul 5, 2013
@Toflar
Copy link
Collaborator

Toflar commented Jul 5, 2013

Not sure this is correct, Kamil. If what @formatz said is true, it's true for every form field, not only for the captcha field! So what your solution does is this:

// now works
$_SESSION['FORM_DATA']['captcha_myFormId'] = 'foobar';  // captcha form 1
$_SESSION['FORM_DATA']['captcha_myOtherFormId'] = 'barfoo'; // captcha form 2

// still doesn't work
$_SESSION['FORM_DATA']['myFormField'] = 'foobar'; // my form field of form 1
$_SESSION['FORM_DATA']['myFormField'] = 'foobar'; // my form field of form 2

Correct would be this

$_SESSION['FORM_DATA']['myFormId']['captcha'] = 'foobar';  // captcha form 1
$_SESSION['FORM_DATA']['myOtherFormId']['captcha'] = 'barfoo'; // captcha form 2
$_SESSION['FORM_DATA']['myFormId']['myFormField'] = 'foobar'; // my form field of form 1
$_SESSION['FORM_DATA']['myOtherFormId']['myFormField'] = 'foobar'; // my form field of form 2

@qzminski
Copy link
Member

qzminski commented Jul 5, 2013

I think the problem was with multiple captchas, as they were not validated correctly? @formatz, can you precise what was the problem?

@formatz
Copy link
Author

formatz commented Jul 8, 2013

Yes @qzminski , the problem was the validation.
Only the last Captcha key and data were saved in Session (they all overwrites the same key in session array).

@Toflar
Copy link
Collaborator

Toflar commented Jul 8, 2013

Only the last Captcha key and data were saved in Session (they all overwrites the same key in session array).

But that's what I was saying. That's the case for all form fields that have the same name. So if you have two forms with the form field name vehicle, the second one is going to overwrite the first one :-)

@formatz
Copy link
Author

formatz commented Jul 8, 2013

Perhaps I don't understand your problem.
For me it doesn't matter that each forms contain the same input names because only the values from the submitted form are sent (each form id is unique and I can check the "FORM_SUBMIT" value).
(I compute the DCA values from a specific table. I didn't use the form generator)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants