Sorry if this is an obvious question/answer but I just cannot get it to work... I have a Safecracker form on the front end. I have Playa to create a single relationship field with another channel. How do I show a list of entries from the other channel linked using Playa in a Safecracker form? There seems to be little documentation online, all solutions I found dont work and end up with {option_name} in the drop down.
Thanks
How do you show a select options list of a field related using playa in a Safecracker form?
-
OK I got it working using only:
[quote]{field:my_playa_field}[/quote]
Although its taken Playas styling and put my form out of whack. At least I found the solution on this support site somewhere.
I dont think the documentation is very good, there is very little about this online. -
-
Hi Laurie,
If you want to customize the output, you could do something like this:
<select name="playa_field[selections][]">
{exp:channel:entries dynamic="no" channel="my_channel"}
<option name="{entry_id}">{title}</option>
{/exp:channel:entries}
</select> -
-
Thanks for your reply... to confirm a few things...
First this is in a {exp:safecracker} tag, I have found out today that the exp:channel: entries tag does not work inside the safecracker pair. Do you know about this? I posted it on EE earlier, someone else reported it too.
So I tried your code but just get a blank drop down. I dont know if I have your code wrong or its because channel entries not working in safecracker.
To clarify your code, if I have "Pupils" who are members of "Schools", so in a safecracker form I want to add a pupil and choose the school they are a member of from a dropdown. This is a Playa field. Would your code be:-
<select name="school[selections][]">
{exp:channel:entries dynamic="no" channel="school"}
<option name="{entry_id}">{title}</option>
{/exp:channel:entries}
</select>
I want to be sure I have your code correct before I decide its not working, or the safecracker is not working.
Thanks -
-
Here's the EE post on channel entries inside a safecracker:
http://expressionengine.com/forums/vi... -
-
The only way I got it working so far is to use this:
{field:participant_school}
BUT to get it look like a normal unstyled drop down the field needs to be a EE Relationship field (which is OK for one to one but does not support one to many) OR if it's a Playa field (for one to many) then the style is not what I want, Playa styles it as per another post I made earlier with screenshot. -
-
So rather than putting the code directly in the same template as your Safecracker tags, put it in an embedded template.
So where you want the select, put this:
{embed="site/_playa_select"}
Then create a site/_playa_select template, with the code I sent earlier. -
-
Ah genius! Of course. This works, I can now get the select list using channel entries in the safecracker form.
BUT I have errors, there are two scenarios depending on the code I use.
I wasn't sure if in your code I leave playa_field in (so select name="playa_field[selections][]") or change this to the playa field name (so select name="school[selections][]").
If I use your exact code leaving playa_field in, it does not save the selection entry, school, for the pupil I am adding.
If I change "playa_field" to "school" then I get:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: This is My School Name
Filename: playa/ft.playa.php
Line Number: 1978
So I must have an error in adding the select form as the playa field.
I am sure I am almost there!
Thanks -
-
Yes, you should replace “playa_field” with your actual Playa field name.
What version of Playa are you using? -
-
I only downloaded playa a few days ago, so version 4??
I get the above error when replacing playa_field with my fieldname.-
Oops I'm logged in with a different google account, it's me, Laurie :)
-
-
-
-
-
Sorry! When I wrote:
<option name="{entry_id}">{title}</option>
“name” should have been “value”:
<option value="{entry_id}">{title}</option> -
-
Yes its working horay!!! Doh, I should have spotted that too. Its always the silly mistakes you spend ages trying to fix.
So all seems to be working OK now. I got a safecracker form with a Playa select field in it. I do think there is not much documentation on this though, spent ages looking but couldn't find much at all. What I found did not seem to work. May be good having a "front end" Playa section in your documentation?
Anyway, thanks a lot for your help! -
-
Glad that worked.
I probably will be adding a page to the docs about manually creating the field for Safecracker – it’s a question that’s starting to pop up for Matrix and Playa more and more.-
Not in the docs yet... any chance to have it added soon.
-
-
-
-
-
-
Hi Brandon - I've followed this thread and I've tried implementing the same solution using this code in a template, that I then embed in a Safecracker field as per the instructions above.
{exp:channel:entries dynamic="no" channel="favourites"}
{title}
{/exp:channel:entries}
In this example playa_favourites is the field name, and it pulls entries from the favourites channel.
The options show up in my form well enough, but they do not get saved when updating the form. I'm wondering if it has something to do with ?
Any tips/hints/suggestions? -
-
Did you update the <select> name to "playa_favourites[selections][]" ?
-
-
Just realized the code I copied and pasted didn't actually paste.. I'll try that again.
<select name="playa_favourites[selections][]">
{exp:channel:entries dynamic="no" channel="favourites"}
<option value="{entry_id}">{title}</option>
{/exp:channel:entries}
</select>-
I'm going to create a new topic, as this still isn't necessarily the customization I want.
-
-
-
-
-
There is just one issue with this...
Because the Select form is now in its own template, when editing a field the Select form does not know what the chosen value is of the field so it always defaults back to the first one in the list, instead of showing the chosen one:
Edit template:
{embed="venues/_venue_options"}
Select Template:
{exp:channel:entries channel="event" dynamic="no" limit="1"}
{preload_replace:event_venue_id="{event_venue}{entry_id}{/event_venue}"}
{/exp:channel:entries}
{exp:channel:entries dynamic="no" channel="venue"}
{event_venue_id}{title}
{/exp:channel:entries}
I tried passing variables from the the Edit template to the Select template but cant get then to work, wondered if anyone had any tips on this.
Thanks -
-
Change your embed to:
{embed="venues/_venue_options" selected="{playa_field:child_ids}"}
And your select template:
{exp:channel:entries dynamic="no" channel="venue"}
<option value="{entry_id}" {if entry_id == embed:selected}selected{/if}>{title}</option>
{/exp:channel:entries} -
-
Ah right, Great this works, thanks a lot.
But I think the first code needs to be wrapped in the channel entries tag, with segment_3 being the entry_id:
{exp:channel:entries channel="event" dynamic="no" entry_id="{segment_3}"}
{embed="venues/_venue_options" selected="{playa_field:child_ids}"}
{/exp:channel:entries}
But I have this in a safecracker form, and I dont think you should have channel entries inside a safecracker? So does that mean I need to include this in another template? I have a template inside a template inside a template then.
If I do include the channels entry tag inside the safecracker its showing 3 empty forms (the number of entries I have in the channel) -
-
Oh its OK... for the above post I tried putting the channel entries tag around my whole form because I have a few drop downs and did not want to repeat the channel entries tag, I thought it would work putting the whole form in it but it just repeated the form when no entry_id existed.
But if I use the above code on the SELECT input only it works, and I just repeat this for each SELECT drop down I have.
So seems to be working OK! Thanks a lot. -
-
I am SO close to getting this right (lots of other Playa + Zoo Visitor hurdles last week)...
I have nearly the same situation, but I need checkboxes. I can grab all the checkbox values and displays fine in safecracker/zoo_visitor registration form. All data submits and registers great except for the playa field I have the following:
I thought it would work, but it didn't. Since The checkboxes and values render, I didn't see the need to an embed. Anything you can see? Thanks.<input type="hidden" value="" name="playa_commodities[selections][]">
{exp:channel:entries channel="commodities" dynamic="no" orderby="title" sort="asc"}
<span class="checkHolder">
<label class="label_check" for="playa{entry_id}">
<input type="checkbox" id="playa{entry_id}" name="playa_commodities[]" value="{entry_id}"> {commodity_name}
</label>
</span>
{/exp:channel:entries}
... BTW - did get it to work with
as described above, but isn't enough for this need. At the last minute I added the hidden field to my checkbox example. Would that have messed me up?<select name="playa_commodities[selections][]">
{exp:channel:entries channel="commodities" dynamic="no" orderby="title" sort="asc"}
<option value="{entry_id}">{commodity_name}</option>
{/exp:channel:entries}
</select>
And still LOVING Playa. Thanks for the great add-on. -
-
EMPLOYEE
1Hi Michael,
The checkbox names need to be "playa_commodities[selections][]" (you're missing [selections]). -
-
Thanks again, Brandon. Saved me. I think with something earlier in this thread, I'll be able to auto-check their selections on an update form using this same method and passing the child ids. Am I on the right track? Does this require an embed?
That Brit Andy Gaunt said your support was great. He was right. -
-
To check if it was previously selected, you'll need to move that code into an embedded template, because you can’t have an {exp:channel:entries} tag inside another {exp:channel:entries} tag. In your {embed} tag, pass the entry ID that's being edited:
{embed="includes/_playa_checkboxes" entry_id="{entry_id}"}
Then you can do this to determine if an option is selected:
<option value="{entry_id}" {if "{exp:playa:total_children entry_id="{embed:entry_id}" child_id="{entry_id}"}"}selected="selected"{/if}>
{commodity_name}
</option> -
-
Have been looking at this for a while and can't get my selects to populate for some reason. Really stuck on this - and I'm sure it's something simple, but just can't see it.
My code is in the following pastie http://pastie.org/3227414- view 1 more comment
-
-
Hah. Glad you got it working!
-
-
I know EXACTLY how you feel. It looked right to me or what it's worth.
-
-
-
Loading Profile...


Twitter,
Facebook, or email.




