ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Customized SAEF - how to populate dropdowns?

August 27, 2007 9:43am

Subscribe [13]
  • #1 / Aug 27, 2007 9:43am

    chronistin

    104 posts

    For a new project which makes excessive use of custom fields, I need the ability to

    1.) Add and edit content from the frontend
    2.) Customize the frontend forms (i.e. using the standard custom fields tag won’t work)

    I’ve found the (excellent!) Wiki entry for hardcoding the saef, and it works fine - except that I can’t figure out how to get the values for the entry fields that have been defined as dropdown (except hardcoding the option values into the form, but that seems rather crude).

    Any pointers, please?

    I’ve searched the forums & found a reference to solspace’s form_helper, but as far as I could find out, this works only for editing, not for new entries - or am I missing something?

    Thanks, Chronistin

  • #2 / Aug 27, 2007 10:15am

    Phoebe

    58 posts

    Where is the content for your dropdowns coming from?  Is it a related field or are you hard-coding them?

  • #3 / Aug 27, 2007 10:34am

    chronistin

    104 posts

    Well, I’m looking for a solution for both cases, really. Partly these fields have been defined as dropdown in the backend (like a field “year”, which has predefined values from 1980 to 2007), but there’s also a relationship to a gallery.

  • #4 / Aug 27, 2007 11:16am

    Phoebe

    58 posts

    Here is a quick plugin I made from a more customised version.  You could see if this does the job.

    Put something like this in your template:

    {exp:pops:pop_input value="{job_type}" field="job_type"}
       <label for="{field_name}">Job Type</label>
       {popup}
       <input type="hidden" name="{field_format}" value="none" />
    {/exp:pops:pop_input}
  • #5 / Aug 27, 2007 12:14pm

    chronistin

    104 posts

    Thankyou, this works great so far! Is there any way I could keep selected values around for the preview function?

    Same form, different problem: I don’t seem to be able to set the field formatting for “text input”-fields to none. I’ve tried to use

    <input type="hidden" id="field_ft_36" value="none" />

    ...replacing 36 with the relative value, of course.
    But still, all the fields are set to “xhtml” in the database.
    Seems like a strange problem, as the default format value is “none” anyway, so where does that get overruled?

  • #6 / Aug 27, 2007 12:33pm

    Phoebe

    58 posts

    Data should stick around for preview and your code looks fine to me, which suggests the plugin isn’t working correctly.  Can you show the HTML source code being generated by the plugin and the piece of the template that uses the plugin?

  • #7 / Aug 27, 2007 1:19pm

    chronistin

    104 posts

    Sorry, I didn’t express myself clearly, that’s because my head is spinning after 2 days fiddling with this form… I’ll try again. 😊

    - for textareas and textinput I use the method from this wiki entry. This works fine for input and preview, but whatever I try, all the fields default to formatting=xhtml , which is not good for displaying the data later. Fields are set to formatting: none in the backend, plus I tried to add the line

    <input type="hidden" id="field_ft_36" value="none" />

    with the corresponding field-value for every field, but that doesn’t change anything either.

    - for the dropdowns, I now use your plugin (thanks again!), which works great for populating the dropdowns and also retains the formatting. But it doesn’t carry the selections over to the preview.

    - The standard “custom fields”-Tag ist used for the relationships, which works fine so far.

    There’s 40 custom fields in the form, so I’m not gonna post all that repetitive stuff, but an extract with one for each method: (template is called add_entry)

    // this is the php for retaining the value of a field in preview, as posted in the wiki
    <?
    if (isset($_POST['field_id_15'])) {
    $field_id_14 = $_POST['field_id_15'];
    }
    else {
    $field_id_15 = '';
    }
    
    ?> 
    
    // the form tag. show_fields is used for a standard display of related entries:
    
    {exp:weblog:entry_form weblog="weblog" return="weblog/index" preview="weblog/add_entry" show_fields="image_1|image_2|image_3"}
    
    
    // a text field:
    Hours:
    
    <input type="text" dir="ltr" id="field_id_15" name="field_id_15"  value="<?php echo $field_id_15;?>" maxlength="128" size="12" onclick="setFieldName(this.name)" /><input type="hidden" id="field_ft_15" value="none" />
    
    // a dropdown:
    
    Year:
    
    {exp:pops:pop_input value="{year}" field="year"}
       {popup}
       <input type="hidden" name="{field_format}" value="none" />
    {/exp:pops:pop_input}
    
    // at the end of the form, there is this codebit for the relationships:
    
    {custom_fields}{if relationship}
    <select name="{field_name}">
    {options}<option value="{option_value}"{selected}>{option_name}</option>{/options}
    </select>
    {/if}
    {/custom_fields}
    
    // and finally, preview/submit and closing the form tag
    
    <input type="submit" name="submit" value="Save" /> <input type="submit" name="preview" value="Preview" />
    
    {/exp:weblog:entry_form}

    My understanding is that the php-part on top is needed for the preview to work, but I am unsure how to integrate that with the plugin?

  • #8 / Aug 27, 2007 1:35pm

    chronistin

    104 posts

    OK, I found the problem with text formatting - I have to define name, not id for the field. So, please disregard that part.

  • #9 / Aug 27, 2007 1:45pm

    Phoebe

    58 posts

    If this helps, you can use the pops plugin for any field, just leave out the popup bit.  eg.

    {exp:pops:pop_input field="job_description"}
       <label for="{field_name}">Job Description</label>
       <textarea id="{field_name}" name="{field_name}" rows="6" cols="40"></textarea> 
       <input type="hidden" name="{field_format}" value="none" />
    {/exp:pops:pop_input}

    Can you cut out a bit of the HTML that generates the popup as it shouldn’t matter what is generating the html, as long as the field names are correct the values should be available in preview.

  • #10 / Aug 27, 2007 1:45pm

    Phoebe

    58 posts

    Glad that’s sorted.  So have you it working now?

  • #11 / Aug 27, 2007 2:03pm

    chronistin

    104 posts

    Not really, sorry for bothering you one more time. I’m probably just being stupid, but I cannot get the preview to work. Here is the source code resulting, looking the same in the original form and the preview:

    <select id="field_id_14" name="field_id_14">
       <option label="" value="" ></option>
             <option label="2007" value="2007" >2007</option>
             <option label="2006" value="2006" >2006</option>
             <option label="2005" value="2005" >2005</option>
             <option label="2004" value="2004" >2004</option>
     </select>
       <input type="hidden" name="field_ft_14" value="none" />

    So, none of the options gets “selected” for the preview.

  • #12 / Aug 27, 2007 5:04pm

    Phoebe

    58 posts

    OK, done some mods to the plugin.

    DONT pass the value on the add form - it will try and get the value from the POST variables first and only use the value you specify if a POST doesn’t exist.

    So the template should now be

    {exp:pops:pop_input  field="job_type"}
       <label for="{field_name}">Job Type</label>
       {popup}
       <input type="hidden" name="{field_format}" value="none" />
    {/exp:pops:pop_input}

    And for any other field:

    {exp:pops:pop_input field="job_description"}
       <label for="{field_name}">Job Description</label>
       <textarea id="{field_name}" name="{field_name}" rows="6" cols="40">{value}</textarea> 
       <input type="hidden" name="{field_format}" value="none" />
    {/exp:pops:pop_input}

    Let me know if this works

  • #13 / Aug 27, 2007 5:23pm

    Phoebe

    58 posts

    In a fit of enthusiasm I’ve tweaked the plugin to only make one sql call per form (instead of two each time it was used) so there should be almost no time penalty in using it for all fields.

  • #14 / Aug 28, 2007 8:51am

    chronistin

    104 posts

    It works perfectly now! How can I thank you?

  • #15 / Aug 28, 2007 10:28am

    Phoebe

    58 posts

    No problem, glad I spent the time on it, will be useful for me too!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases