5

I am currently building a web app that allows users to create a list of their own contacts which are then stored as channel entries. This generally works fine however the Structure URLs are not being generated as expected.

I have created the form as below. The dynamic title is working and is being set on a simple jquery keyup handler. When I submit the form using ajax, the entry is created along with all the relevant data but rather than the entry being accessed at domain.com/channel/john-doe it is found directly at domain.com/john-doe.

I have gone as far as to use the Structure module's suggested additional tags:

<input type="hidden" name="structure_template_id" value="21" />
<input type="hidden" name="structure_parent_id" value="{structure:parent:entry_id}" />

but there was no joy and I simply experienced the exact same result. Any suggestions? Full code below (not including the additional structure fields).

{exp:safecracker channel="contacts" dynamic_title="[contact_name]" safecracker_head="no" include_jquery="no" return="safecracker/ENTRY_ID" json="yes" id="addContact"}

<input type="hidden" name="contact_list_designation" value="A" id="contact_list_designation"/>
<input type="hidden" name="contact_name">

<div class="content-bar bar light shiny top">
  <div class="section">
    <div class="center">
      <div>
        <div class="title">New Contact</div>
      </div>
    </div>
  </div>
</div>
<div class="grid-container fieldset-holder">
  <fieldset class="inline">
    <label class="grid-25">Type</label>
    <div class="grid-75">
      <div data-toggle="buttons-radio" class="buttonset cf block designation_radios">
        <div class="button grid-33 active-primary active"><span>A</span></div>
        <div class="button grid-33 active-primary"><span>B</span></div>
        <div class="button grid-33 active-primary"><span>C</span></div>
      </div>
    </div>
  </fieldset>

  <fieldset class="grid-50">
    <label>Firstname</label>
    <input type="text" name="contact_firstname">
  </fieldset>
  <fieldset class="grid-50">
    <label>Lastname</label>
    <input type="text" name="contact_lastname">
  </fieldset>
  <fieldset>
    <label>Company</label>
    <input type="text" name="contact_company">
  </fieldset>
  <fieldset>
    <label>Email</label>
    <input type="text" placeholder="name@example.com" name="contact_email">
  </fieldset>
</div>
{/exp:safecracker}
4
<input type="hidden" name="structure_parent_id" value="{structure:parent:entry_id}" />

Yup, this will definitely be required for this to work with Structure ... but is {structure:parent:entry_id} outputting something usable inside your Safecracker form? Check in your rendered page's source, looking at that hidden field. Otherwise, Structure won't know that you want this entry to be assigned to a parent.

| improve this answer | |
  • Yes that does produce a desired value. I had originally assumed that the parent entry id value would simply correspond to the channel id but that doesn't seem to be the case either way. – Conor Higgins Jan 3 '13 at 21:56
  • I'm pretty sure that field will have to contain the entry_id of the parent entry for your URL to end up the way you want it to. – Derek Hogue Jan 3 '13 at 22:12
  • Derek, I think that is what's happening with the above tag, it seems to be generating the necessary tag but the url title is still being generated without the necessary channel prefix, in this case "contacts" – Conor Higgins Jan 3 '13 at 22:17
  • I meant necessary value in this case sorry. – Conor Higgins Jan 4 '13 at 9:51
  • Does Structure normally add the channel name as a prefix to the url_title? Or is another add-on doing that? Doesn't seem to be a standard behaviour. – Derek Hogue Jan 4 '13 at 13:32

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.