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 and preserving relationships

May 30, 2013 3:35am

Subscribe [2]
  • #1 / May 30, 2013 3:35am

    I’m building a function where a user can approve an another users entry (basically a manager can approve an expense form).

    I’m currently using statuses and this code worked fine pre 2.6

    {exp:safecracker channel="expense_report" return="manager/report_approved" include_jquery="no" entry_id="{segment_3}" preserve_checkboxes="yes"}
        <input type="hidden" name="title" id="title" value="{title}" size="50" maxlength="100" >
        <input type="hidden" name="status" id="status" value="Approved">
        <button type="submit" class="btn btn-info">Approve</button>
    {/exp:safecracker}

    However I’m now using the new fancy relationships and it throws a coupple of php warnings and also remove all relationships.

    I assume it’s ok to partially edit an entry using safecracker without the need to include the whole form. It worked fine before and on other places sans relationships

    If I include the code for the relationship it works, but it does NOT work if I hide the checkboxes either with css display:none or type=“hidden”.

    {custom_fields}
        {if relationship}                                            
            {options}
                <input type="hidden" name="{field_name}[sort][]" value="{option_order}" >
                <input type="checkbox" name="{field_name}[data][]" value="{option_value}" class="" {checked}>
            {/options}
        {/if}
    {/custom_fields}

    In the best of worlds safecracker would preserve the relationships through preserve_checkboxes=“yes” or similar. In the meantime maybe someone has a leaner solution?

     

  • #2 / Jul 18, 2013 10:11am

    jphansen

    4 posts

    I’m having the same problem. To summarize:

    If I open a safecracker tag and reference some entry and do not define the relationships field visibly, upon submitting the form, safecracker erases the relationship’s selected value.

    I’ll continue looking for a solution and post here if I find one. I really don’t want to show the user their relationships field value just for the sake of it not being erased.

  • #3 / Jul 18, 2013 10:38am

    jphansen

    4 posts

    I hope this gets addressed or properly resolved, but I solved it by placing the relationships field between the safecracker tags and setting the CSS attribute visibility:hidden

    {custom_fields}
     {if relationship}
      <select  id="{field_name}" name="{field_name}[data][]">
       {options}
        <option value="{option_value}"{selected}>{option_name}</option>
       {/options}
      </select>
     {/if}
    {/custom_fields}

    EDIT: The style definition was stripped in this post, so just add to the select tag a style attribute: visibility:false.

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

ExpressionEngine News!

#eecms, #events, #releases