FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » How to write a custom field check plugin (validate_custom_fields CUSTOM_FIELD_VALIDATE)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
How to write a custom field check plugin [message #168547] Mon, 20 May 2013 17:27 Go to next message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
I use an extra user-field for "City" in the forum registration.
I'll need a plugin that attach into the validation function, that
check that entered response is not equal to "city" or "yes".

I basically only need the declaration, and how to find the value of the field.

Thank You.
Re: How to write a custom field check plugin [message #168548 is a reply to message #168547] Mon, 20 May 2013 17:32 Go to previous messageGo to next message
naudefj is currently offline  naudefj   
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Sample custom_field_validator.plugin:

<?php
plugin_add_hook
('CUSTOM_FIELD_VALIDATE''plugin_custom_field_validator');

function 
plugin_custom_field_validator($array) {
    list(
$field_id$field_name$field_value) = $array;
    return 
'ERROR: '$field_value .' for '$field_name .' is wrong';
}

function 
custom_field_validator_info() {
    return array(
'name' => 'Custom Field Validator',
                 
'desc' => 'Validate custom profile fields.',
                 
'version' => '1.0');
}
?>
Re: How to write a custom field check plugin [message #168549 is a reply to message #168548] Mon, 20 May 2013 17:36 Go to previous messageGo to next message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
A RESPONSE with CODE within 5 minutes !?!

THANK YOU !!
Re: How to write a custom field check plugin [message #168550 is a reply to message #168549] Mon, 20 May 2013 18:28 Go to previous message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
It seems that the caller send an extra parameter $err, and that
the error-string is truncated into one character.
The OK response is zero.
<?php
plugin_add_hook( 'CUSTOM_FIELD_VALIDATE', 'plugin_custom_field_validator');

function plugin_custom_field_validator( $array) 
{
   list( $err, $field_id, $field_name, $field_value) = $array;
   if ( $field_name == 'City')
   {
      $f_test = strtolower( trim( $field_value));
      if ( $f_test == 'city' || $f_test == 'yes')
      {
         return 'ERROR';
      }
   }
   return 0;
}

function custom_field_validator_info() 
{
    return array( 'name' => 'Custom Field Validator',
                  'desc' => 'Validate custom profile fields.',
                  'version' => '1.0');
}
?> 
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Just started working with FUD Forum
Next Topic: Referrals for someone to install for me
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 02:03:22 GMT 2024

Total time taken to generate the page: 0.02848 seconds