Safecracker entry relationship field
Posted: 03 December 2010 04:37 PM   [ Ignore ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Hi,

I need to have a safecracker dropdown field with available related entries listed, is this possible? I can’t seem to work it out, the code below isn’t working - I just get {option_name} in the dropdown list.

asset_parent is the name of the relationship field.

<label>Parent campaign:</label>
<
select name="asset_parent" id="asset_parent">
    
{options:asset_parent}
        
<option value="{option_value}"{selected}>{option_name}</option>
    
{/options:asset_parent}
</select

Any help is appreciated!

Thanks.

Profile
 
 
Posted: 03 December 2010 09:13 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Try this:

<label>Parent campaign:</label>
{field:asset_parent} 
Profile
 
 
Posted: 03 December 2010 09:22 PM   [ Ignore ]   [ # 2 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Yes! Thanks Rob.

Profile
 
 
Posted: 06 December 2010 01:34 AM   [ Ignore ]   [ # 3 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

I need to limit the parent options in the dropdown to only entries that were created by the logged in user. is this possible?

Profile
 
 
Posted: 06 December 2010 02:02 AM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I think you’ll have to do some kind of custom sql query. Maybe ask around on the EE forums for help on creating that query?

Profile
 
 
Posted: 14 December 2010 11:22 PM   [ Ignore ]   [ # 5 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Hi Rob,

I’m afraid, being a big newbie to EE I dont know how to do that, so I will ask in the EE forums as you suggest.
I found this however and thought I’d post it here in the off chance it gives you any extra inspiration… grin

http://expressionengine.com/archived_forums/viewthread/123776/


Also, the original code i posted, does that not work because Safecracker can’t can’t read relationship fields liek that or just because the code itself is wrong?

[ Edited: 14 December 2010 11:26 PM by jamestowers ]
Profile
 
 
Posted: 14 December 2010 11:44 PM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

This should do the trick. Make sure you have the query module enabled. Enable PHP in your template, parsed on input, and replace channel_id = 1 with the channel id of the relationship channel.

<label>Parent campaign:</label>
<
select name="asset_parent" id="asset_parent">
        <
option value="">--</option>
{exp:query sql="SELECT entry_id AS rel_entry_id, title AS rel_title, (SELECT rel_child_id FROM exp_relationships WHERE rel_id = '{asset_parent}' LIMIT 1) AS rel_child_id FROM exp_channel_titles WHERE channel_id = 1 AND author_id = <?php echo $this->EE->session->userdata('member_id'); ?>"}
        
<option value="{rel_entry_id}"{if rel_child_id == rel_entry_id} selected="selected"{/if}>{rel_title}</option>
{/exp:query}
</select
Profile
 
 
Posted: 14 December 2010 11:54 PM   [ Ignore ]   [ # 7 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Rob, you’re a star, thank you so much.

Profile