-
Notifications
You must be signed in to change notification settings - Fork 525
Modulebuilder: form validation callback functions do not work #295
Comments
Hi @jmalinens Where do they not work? In the Builder itself or in the generated module? The no_match callback worked for me when I tried it in the Builder. The documentation doesn't say anything about passing $this into the run method only a group. Could you give some more info? Thanks |
problem is in generated module public function captcha_check($nResult)
{
if ($nResult != 4)
{
$this->form_validation->set_message('captcha_check', 'You have problems with basic math or you are spam robot...');
return FALSE;
}
else
{
return TRUE;
}
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// !PRIVATE METHODS
//--------------------------------------------------------------------
/*
Method: save_requests()
Does the actual validation and saving of form data.
Parameters:
$type - Either "insert" or "update"
$id - The ID of the record to update. Not needed for inserts.
Returns:
An INT id for successful inserts. If updating, returns TRUE on success.
Otherwise, returns FALSE.
*/
private function save_requests($type='insert', $id=0) {
$this->form_validation->set_rules('body', 'Request_text', 'required|trim|xss_clean|max_length[500]');
$this->form_validation->set_rules('category', 'Request_category', 'required|trim|xss_clean|alpha');
$this->form_validation->set_rules('e-mail', 'Email', 'trim|xss_clean|valid_email|max_length[45]');
$this->form_validation->set_rules('stupid_captcha', 'Captcha', 'callback_captcha_check');
$_POST['languages_id'] = $this->lang->lang_id();
if ($this->form_validation->run($this) === FALSE) {
return FALSE;
} without adding $this, callback function does not run |
Is that in one of your modules? I don't recognise the code but maybe I'm still half asleep :| Are you requesting that the change be made to the Module Builder code itself or the module code that gets generated? |
Module generator should genereate $this->form_validation->run($this) everywhere instead of $this->form_validation->run(). this is something to do with Form_validation.php library line 588:
because of HMVC form validation library "can't see" if callback method exists or not so it skips running callback. |
I thought you just needed to add
To make the form_validation library work with HMVC |
I'm not sure on this - which solution should we go with? @svizion Where would your line of code go? |
That is what I always thought you had to do to make Form Validation work with HMVC or atleast that is what I found on CI Forums. It's already in use in Auth and Admin_Controller. |
@svizion Ah indeed it is - thanks for that. @jmalinens thanks for finding this but we will go with the way it has been resolved in Bonfire already. Thanks |
Hmm so if it's already done in the Authenticated_Controller how is it still not working? The form_validation is loaded before the module is loaded so where would we put the code in the module? |
Strange in the Forum post he referenced It says you can do it either way
or this
Strange since your using a captcha code, is this on the front_end controller ? |
Yes, front end controller:
We are taking too much time on this issue- not very important :D |
Ah right. The front end controller is up to the developer really but I'll have a look at the code for it. Thanks |
@jmalinens @svizion That should be it now. |
http://codeigniter.com/forums/viewthread/176150/#969627
We need to use
if ($this->form_validation->run($this) === FALSE)
instead of
if ($this->form_validation->run() === FALSE)
everywhere
The text was updated successfully, but these errors were encountered: