Welcome Guest, Not a member yet? Register   Sign In
Form Validation Callback
#8

(04-10-2017, 03:51 AM)InsiteFX Wrote: Try this:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ----------------------------------------------------------------------------
 * Editor   : PhpStorm 2017.1.1
 * Date     : 2/5/2017
 * Time     : 6:29 AM
 * Authors  : Raymond L King Sr.
 * ----------------------------------------------------------------------------
 *
 * Class        MY_Form_validation
 *
 * @project     csdmodule
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2017 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ----------------------------------------------------------------------------
 */

/**
 * Class MY_Form_validation
 *
 * place into ./application/libraries
 * 
 * use like this
 * if ($this->form_validation->run($this) == FALSE)
 * {
 *
 * }
 * else
 * {
 *
 * }
 */
class MY_Form_validation extends CI_Form_validation
{

    
/**
     * Class properties - public, private, protected and static.
     * ------------------------------------------------------------------------
     */


    // ------------------------------------------------------------------------

    /**
     * run ()
     * ---------------------------------------------------------------------------
     *
     * @param   string $module
     * @param   string $group
     * @return  bool
     */
    
public function run($module ''$group '')
    {
        (
is_object($module)) AND $this->CI = &$module;

        return 
parent::run($group);
    }

    
// ------------------------------------------------------------------------

  // End of MY_Form_validation Class.

/**
 * ----------------------------------------------------------------------------
 * Filename: MY_Form_validation.php
 * Location: ./application/libraries/MY_Form_validation.php
 * ----------------------------------------------------------------------------
 */ 

(04-10-2017, 11:16 AM)Paradinight Wrote:
(04-10-2017, 11:02 AM)RBX Wrote:
(04-10-2017, 03:51 AM)InsiteFX Wrote: Try this:

That should do it. For now, I've avoided the callback validation rule.

(04-10-2017, 03:53 AM)salain Wrote: According to the documentation your callback should not start with the underscore
see callback
This rule applies to router, and not the PHP itself, therefore it shouldn't cause a problem, and it really doesn't. Also, I can't find mention of what you say on the given link.

$this->fv->set_message(__METHOD__, 'Incorrect {$field}');

change __METHOD__ to _verifyPassword.
make a var_dump to __METHOD__ Tongue
edit:

http://php.net/manual/en/language.consta....php#57033

Yeah, I should have used __FUNCTION__ instead. I can't dump that constant, the method never gets called. Smile

(04-11-2017, 12:01 AM)salain Wrote: @RBX

If you look at the rule and the actual method in the link I am referring as well as into the Form_validation library.

You will see that if you have a callback rule like this:


PHP Code:
$this->form_validation->set_rules('username''Username''callback_username_check'); 


Your method has to be :


PHP Code:
public function username_check($str)
 
    {
 
               ......
 
    

This is because the Form_validation library removes the first 9 characters from the callback method name in the rule,  so it includes the underscore. So if you want your method name to start with an underscore you need to double it in the rule:

PHP Code:
$this->form_validation->set_rules('username''Username''callback__username_check');

.....


public function 
_username_check($str)

 
       {
..... 

Yes, and as can be seen, I'm already using double underscores. It's intentional as validation callbacks need to be public, but I don't want them to be accessible by URL.
Reply


Messages In This Thread
Form Validation Callback - by RBX - 04-10-2017, 01:29 AM
RE: Form Validation Callback - by InsiteFX - 04-10-2017, 03:51 AM
RE: Form Validation Callback - by salain - 04-10-2017, 03:53 AM
RE: Form Validation Callback - by InsiteFX - 04-10-2017, 08:52 AM
RE: Form Validation Callback - by RBX - 04-10-2017, 11:02 AM
RE: Form Validation Callback - by Paradinight - 04-10-2017, 11:16 AM
RE: Form Validation Callback - by salain - 04-11-2017, 12:01 AM
RE: Form Validation Callback - by RBX - 04-11-2017, 08:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB