Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2011, 11:42 AM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How can I check a custom option before saving?

Hello everyone, I was wondering if someone could please help me in a concern I am having with one of my custom options I created. Allow me to explain;

I have the following options:

Option A: yes no

Option A1: blah1

Option A2: blah2

Option A3: blah3

I want to be able to force the user to fill out options A1, A2, and A3 if they click yes for option A. I have an option that if turned on or selected yes, 3 other options have to be filled out for the option to execute correctly so I don't want the user to be able to save if the other 3 options have not been filled out yet. Is there any way I can get this done? I would imagine I can use a code in the Validation php code filed , some sort of if condition maybe? I am just not entirely sure how to go about it. If anyone can shed any light on this matter or can provide any more info it would be very much appreciated as always. Thanks for your time everyone.
Reply With Quote
  #2  
Old 08-15-2011, 01:39 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you create a plugin using hook profile_updateoptions, you can check the values and if they aren't correct, call eval(standard_error()), like

PHP Code:
if (some check for values fails)
    eval(
standard_error("Some error message")); 

Look in profile.php, search for fetch_hook('profile_updateoptions') (around line 2411) to see how the values are stored.
Reply With Quote
  #3  
Old 08-15-2011, 02:24 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
If you create a plugin using hook profile_updateoptions, you can check the values and if they aren't correct, call eval(standard_error()), like

PHP Code:
if (some check for values fails)
    eval(
standard_error("Some error message")); 

Look in profile.php, search for fetch_hook('profile_updateoptions') (around line 2411) to see how the values are stored.
Thank you so much. Sounds easy enough. One question though what is the purpose of the area for PHP Validation Code where you set the options? Thanks anyway for your help. I'll try it out and let you know how it went.
Reply With Quote
  #4  
Old 08-15-2011, 02:39 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm...validation code? Maybe I misunderstood and we're talking about different kinds of options.
Reply With Quote
  #5  
Old 08-15-2011, 02:43 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
hmm...validation code? Maybe I misunderstood and we're talking about different kinds of options.
I was talking about the options (custom options) you can create when in debug mode from the admin panel under "Settings".
Reply With Quote
  #6  
Old 08-15-2011, 02:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh...my mistake, I thought you meant custom profile fields. So what I posted above is useless. I don't have time right now but I'll look in to it later if you don't have an answer yet.
Reply With Quote
  #7  
Old 08-15-2011, 03:11 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Oh...my mistake, I thought you meant custom profile fields. So what I posted above is useless. I don't have time right now but I'll look in to it later if you don't have an answer yet.
xD Thanks kh99, it's ok. Please let me know if you find an answer when you have a chance, you know where to find me .
Reply With Quote
  #8  
Old 08-15-2011, 08:17 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Personally I think you're best off using a plugin to check values and throw the error.

Hook the plugin to admin_options_processing and compare $settings['your_setting_name'] and throw the error if it's not correct or empty.

I don't know if that's the absolute correct hook, but I think it will work. Otherwise, you have to intercept $data before it's written to the settings database.
Reply With Quote
  #9  
Old 08-15-2011, 11:11 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
Personally I think you're best off using a plugin to check values and throw the error.

Hook the plugin to admin_options_processing and compare $settings['your_setting_name'] and throw the error if it's not correct or empty.

I don't know if that's the absolute correct hook, but I think it will work. Otherwise, you have to intercept $data before it's written to the settings database.
Hey nhawk, thanks for your reply. I tried something like what you suggested;

PHP Code:
if ($settings['cotw_sotw_pay_credits']  == 1)  {


    if (empty(
$settings['cotw_sotw_first_place_prize'])) {
            
$error 'invalid_value';
                    return 
false
        if (empty(
$settings['your_setting_name'])) {
                 
$error 'invalid_value';
                         return 
false
            if (empty(
$settings['your_setting_name'])) {
                                
$error 'invalid_value';
                                        return 
false;  
             }
         }
   }
    

When the bottom 3 options are empty (or any of the three for that matter), this will still save the options but give them value of "0" if they were empty when the option was saved. That's better than saving it without any value at all I suppose. Would much rather see the error on the field it's missing, I'm doing something wrong in this code because the error does not print out anywhere on the page, just saves and reloads. The good part is that I know now how to control these options and it's requirements to save and such, that hook you mentioned works just fine for my purposes btw, now it's just a matter of printing the error in the missing field(s). Anyone have any ideas? :erm:
Reply With Quote
  #10  
Old 08-15-2011, 11:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What you have is probably the best way to keep invalid values from being saved. The PHP Validation code will allow you to check a value and print a message under it if it's invalid, but it will still be saved (maybe you knew that already and that's why you created the thread).

What you might be able to do in your plugin is print an error message then redirect back to the option page like:

PHP Code:
define('CP_REDIRECT''options.php?do=options&dogroup=' $vbulletin->GPC['grouptitle']);
print_stop_message('error_phrase'$vbulletin->GPC['title']); 

(You'd want to use a real error phrase name, but I'm not sure of the other parameters you'd want). I don't think there's any easy way to get the error message to display under the value unless you let it save the invalid values (that is a reasonable option - you could check the values the mod code and use defaults if they're invalid, put in PHP validation code for your fields, and then whenever someone goes to the adminCP they'll see the error message).
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:53 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04211 seconds
  • Memory Usage 2,264KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete