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.

Selected categories in SAEF Edit

November 03, 2009 1:53am

Subscribe [3]
  • #1 / Nov 03, 2009 1:53am

    wecreateyou

    86 posts

    Has any progress been made getting categories (checkboxes or selects) to show checked or highlighted in a stand alone edit form?

    A wiki article mentions it didn’t work for the author and the follow-up discussions have some ideas that ultimately did not work either.

  • #2 / Nov 03, 2009 12:50pm

    ender

    1644 posts

    I don’t know how others are doing it, but here’s what’s worked for me… note that the following code was written to show just the parent categories (my edit form used categories perhaps a bit differently than most).  Still, it should be easy to modify to work in the general case.

    <select name="category[]" id="main_category" size="1">
        <option value="">-- Select a Category --</option>
        {exp:query sql="SELECT
                            c.cat_id,
                            c.cat_name,
                            p.selected
                        FROM
                            exp_categories AS c LEFT JOIN
                            (
                                SELECT cat_id, 'selected' AS selected FROM exp_category_posts WHERE entry_id='{entry_id}'
                            ) AS p ON c.cat_id=p.cat_id
                        WHERE
                            c.parent_id='0' AND
                            c.group_id='3'
                        ORDER BY c.cat_order ASC;"}
            <option value="{cat_id}" {if selected == "selected"}selected="selected"{/if}>{cat_name}</option>
        {/exp:query}
    </select>
  • #3 / Nov 03, 2009 1:10pm

    wecreateyou

    86 posts

    After a quick test, this seems to be exactly what I need. Thanks Ender, that really helps.

  • #4 / Nov 03, 2009 1:22pm

    ender

    1644 posts

    no problem, glad it worked for you.

  • #5 / Nov 23, 2009 10:12am

    gertjanvanlaar

    1 posts

    Thanks, it helped me out too

  • #6 / Nov 23, 2009 10:47am

    ender

    1644 posts

    good to hear 😊

  • #7 / Nov 23, 2009 3:09pm

    Adam Khan

    319 posts

    Great succinct how-to—thanks!

  • #8 / Apr 23, 2010 11:42am

    lincolnpixel

    83 posts

    Hi ender,
            just to let you know… it helped me out too !!

  • #9 / Apr 23, 2010 11:53am

    ender

    1644 posts

    glad this code has helped so many people.  makes me wonder how many people saw it and didn’t post 😊

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

ExpressionEngine News!

#eecms, #events, #releases