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 :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
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 13:27 Go to next message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 13:32 Go to previous messageGo to next message
naudefj is currently offline  naudefj   
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
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 13:36 Go to previous messageGo to next message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 14:28 Go to previous message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma: 0
Member
add to buddy list
ignore all messages by this user
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');
}
?> 
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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: Mon Oct 16 22:09:22 EDT 2017

Total time taken to generate the page: 0.00633 seconds