22 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 500+ items on Envato Market
+2 more
NeutrinoTeam says

Hi there,

I’m implementing the OptionTree in my WordPress new template. I’ve set all settings with option tree and everything works great. Two things I would love to know:

1. Is it possible to make a field required (mandatory), that cannot be left empty for example. 2. Is there a way to validate to input ?

Thanks.

922 posts
  • Has referred 500+ members
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 500+ items on Envato Market
+13 more
MDNW says

Hi Neutrino!

Good question! It might be best to post this over at http://wordpress.org/tags/option-tree, but I’ve been working with OT a lot and haven’t really run across this feature yet… usually I use a fallback of sorts… something like this can be handy:

if(ot_get_option('frontpage_post_count')) :  
    $fp_post_count = ot_get_option('frontpage_post_count');
else : 
    $fp_post_count = -1;
endif;

That basically just checks for a value, and sets a fallback value in case the user hasn’t filled it out yet.

Alternatively, you can do it with markup… for instance, I use something like this for the user’s logo… if they’ve uploaded something, we naturally want to use their image… but if they haven’t uploaded an image, we’ll want to use their “Site Title” and “Site Description” that they setup in their general settings panel:

<a href="<?php echo home_url(); ?>/" title="<?php echo bloginfo('blog_name'); ?>">
    <h1 id="logo" class="sixteen columns">
        <?php if(ot_get_option('logo')) { 
            $logopath = ot_get_option('logo'); ?>
            <img id="logotype" src="<?php echo $logopath; ?>" alt="<?php echo bloginfo('blog_name'); ?>" />
            <?php } else { ?>
                <?php echo bloginfo('blog_name'); ?>
                <br />
            <span><?php echo get_bloginfo('description'); ?></span>            
        <?php } ?>                        
    </h1>
</a>

I could probably tidy that second one up a bit for the sake of clarity, but hopefully that’ll give you the basic idea.

Cheers! B

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

Enque a custom jquery file and make jquery validations? :-)

Fallbacks are a great idea with or without the validation.

4344 posts ThemeForest Reviewer
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Member of the Envato Team
+12 more
Ivor Envato team says

Why would you do that? Never force your users to enter information. That’s against one of the design principles:

Flexibility in Use: The design accommodates a wide range of individual preferences [...]”

Use conditionals and make sure the layout doesn’t break if the field has not been set.

1031 posts It's in the pipeline!
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
+7 more
purethemes says

Hi Neutrino!

Good question! It might be best to post this over at http://wordpress.org/tags/option-tree, but I’ve been working with OT a lot and haven’t really run across this feature yet… usually I use a fallback of sorts… something like this can be handy:

if(ot_get_option('frontpage_post_count')) :  
    $fp_post_count = ot_get_option('frontpage_post_count');
else : 
    $fp_post_count = -1;
endif;

ot_get_option already has “default” value: of_get_option($id,$default);

so you could just write
ot_get_option('frontpage_post_count',-1) 
:)

I’m writing this in case someone missed it, I think in first version of OT it wasn’t working like this.

Cheers

707 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

so you could just write
ot_get_option('frontpage_post_count',-1) 
:)

I’m writing this in case someone missed it, I think in first version of OT it wasn’t working like this.

Cheers

+1 – That function works just like get_theme_mod and get_option.

22 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 500+ items on Envato Market
+2 more
NeutrinoTeam says

Thanks for the replies.

@Ivor – I do understand your point of view, but sometimes you can save a lot of time for a confused customer who just don’t understand what’s wrong in the string format he or she filled in. But in general I really agree with what you have said.

I’m surprised that such a nice framework does not include validation and more flexibility. I was surprised that there is no date picker as well. But bottom line it satisfied.

by
by
by
by
by
by