Setting relationship field when adding channel using SAEFCracker
Posted: 09 January 2011 11:28 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  4
Joined  2010-12-04

I have two channels that are related, Artist and Artwork.  I use SAEFCracker to allow the artist to add artwork.  However, I do not want the artist to have to use the drop sown select menu for the relationship field in the artwork channel when he is doing the submit (too great a chance they will select the wrong artist).  Instead I want to use a hidden field or something to set the relationship field so it relates to the artist who is doing the add automatically.  I can only guess that I will have to write some sql update code that creates a new relationship entry and updates it with the entry id of the artist and the entry id of the artwork.  Problem is I don’t know what the entry id of the artwork is until after the form has been posted and the artwork entry is created.  Does this make any sense?  Any idea on how to handle this?

Profile
 
 
Posted: 09 January 2011 12:11 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

You should just be able to use a hidden input with the entry_id of the artist as its value.

Profile
 
 
Posted: 11 January 2011 02:19 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  4
Joined  2010-12-04

After looking at I can see how that the ee database relationship table I can see how that would work.  Much easier than I thought it would be.  Thank you.

Profile
 
 
Posted: 14 January 2011 09:41 PM   [ Ignore ]   [ # 3 ]
Wallflower
Rank
Total Posts:  4
Joined  2010-12-04

after looking at it again I am not sure how I would setup the form so that I can force the relationship field to contain what I need.  I don’t want the user to see the select field.  I would like to hide it and fill it in myself.  Do I have to use jquery to step in front of the form submission and change the select value?  Have you done this before?  Sorry but I think I am in over my head with this one.

Profile
 
 
Posted: 14 January 2011 09:50 PM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

This should do it:

<input type="hidden" name="THE_NAME_OF_YOUR_RELATIONSHIP_FIELD" value="THE_ENTRY_ID_OF_THE_ARTIST" /> 

Obviously, you need to replace those with the real things.

Profile
 
 
Posted: 15 January 2011 10:00 AM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  4
Joined  2010-12-04

Thanks, that worked.  I thought I had to use a select field since that is how the relationship field is represented in in the form.

Profile
 
 
Posted: 16 January 2011 03:19 AM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Nah, the backend doesn’t care what kind of element it came from, all it cares about is the value smile

Profile