ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker Category Required

January 23, 2012 8:41pm

Subscribe [3]
  • #1 / Jan 23, 2012 8:41pm

    Bransin

    157 posts

    Is there a way to at least make the category array required?

    {exp:safecracker site="site1" channel="test_channel1" include_jquery="no" safecracker_head="no" rules:category="required" error_handling="inline"}

    I’ve also tried

    rules:category[]="required"

    My categories are in a select option setup like the 2nd example here

  • #2 / Jan 24, 2012 12:20pm

    thefifthlion

    133 posts

    Interested to know the same thing.

  • #3 / Jan 24, 2012 9:08pm

    Dan Decker

    7338 posts

    Hey Bransin,

    My testing seems to indicate that the rules: parameter doesn’t support the category field, at least not as a select option. I invite and encourage you to submit this as a Feature Request!

    Thanks for your input!

  • #4 / Feb 25, 2012 4:33pm

    Bransin

    157 posts

    Figured out a simple solution by writing an extension that uses the safecracker_submit_entry_start hook. This is all that is required along with the typical EE extension code.

    // $safecracker is the object
    function sc_category_required($safecracker)
    {
     $this->EE->form_validation->set_rules('category[]', 'Category', 'required|integer');
    }

    Once the extension is enabled, the inline error condition works below.

    {if error:category[]}
    <span class="error">Select a Category</span>
    {/if}
  • #5 / Feb 27, 2012 1:42pm

    Dan Decker

    7338 posts

    Hey Bransin!

    Fantastic!

    Thanks for sharing your solution and code. I’m sure others in the Community will find this useful!

    Is there anything else I can assist you with?

    Cheers,

  • #6 / Feb 27, 2012 9:08pm

    Bransin

    157 posts

    No, thanks Dan! Problem solved.

  • #7 / Feb 28, 2012 3:11pm

    Shane Eckert

    7174 posts

    Bransin,

    That’s awesome! I am glad to see that Dan was able to help you out.

    Thanks again for using the ExpressionEngine forum to post your question!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases