22 posts
  • Bought between 500 and 999 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Israel
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
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
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Power Elite Author
  • Most Wanted Bounty Winner
  • Bought between 500 and 999 items
  • Referred between 500 and 999 users
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
  • Won a Competition
+8 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
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 100 and 199 users
+2 more
duotive says

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

Fallbacks are a great idea with or without the validation.

4317 posts ThemeForest Reviewer
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Venezuela
  • Has been a member for 5-6 years
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor Reviewer 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.

990 posts It's in the pipeline!
  • Elite Author
  • Exclusive Author
  • Europe
  • Has been a member for 5-6 years
  • Bought between 100 and 499 items
  • Referred between 200 and 499 users
  • Envato Studio (Microlancer) Beta Tester
+2 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
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
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
  • Bought between 500 and 999 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Israel
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
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