1

I have a channel called projects and a channel called project_update.

I'm using a reverse relationship to link project updates to a project. This allows the user to post a project update to a specific project.

The project page has a safecracker form at the bottom to allow them to post a project update to that project.

The problem I have is currently the user needs to select from a dropdown list which project he wants to post the update to. Instead of giving him the option I need it to look at the project he's currently in and automatically fill the relationship field with this project.

I heard that Playa has an autocomplete features but this looks like a search box that autocompletes as you type. This is no good to me.

Was wondering if anybody has any solutions to this.

This is the code I currently have, it lists all the projects owned by the member but I need it to list only the current project.

 {exp:safecracker channel="project_update" include_jquery="no" return="projects"}
<p>
 <label>Update the following Project</label>
<select name="relationshiplink" id="relationshiplink">
{exp:query sql="SELECT entry_id AS rel_entry_id, title AS rel_title, (SELECT rel_child_id FROM exp_relationships WHERE rel_id = '{relationshiplink}' 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>  
</p>
  {/exp:safecracker}
2
  • How is the "current project" defined? By the URL being visited? Or is each member tied to one specific project via authorship? Or something else? – Derek Hogue Jan 16 '13 at 11:01
  • Hiya, it's by the URL being visited. – Andy Thorpe Jan 16 '13 at 11:42
4

Since your project area is determined by the URL, you can just query the URL to get the entry_id of your project, and add that to a hidden field:

{exp:query sql="SELECT entry_id AS project_entry_id FROM exp_channel_titles WHERE url_title = '{segment_3}' AND channel_id = 1"}
    <input type="hidden" name="update_project[selections][]" value="{project_entry_id}" />
{/exp:query}

You'll have to change/check three things here:

  • the channel_id (it should be the ID of your Projects channel)
  • the URL segment where your url_title lives (I have it as segment_3 here)
  • the short name of the Playa field in your Updates channel (I have it as update_project here).
2
  • if you're already displaying the project itself above the form, then you can probably fetch the entry_id from there. – GDmac Jan 16 '13 at 13:48
  • Ah, didn't see that - yes, that would work as well. – Derek Hogue Jan 16 '13 at 14:09
1

if you already display the project itself above the form, then you can probably copy / pick-up the entry_id (with stash or mx_jumper) and insert/output it into a hidden field of the safecracker form.

Check out the normal relation dropdown html first, as to what the field name is and what form the value is in. You can assemble a input-hidden field accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.