1 of 2
1
Customized SAEF - how to populate dropdowns?
Posted: 27 August 2007 06:43 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 07:15 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
Posted: 27 August 2007 07:34 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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.

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 08:16 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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}

File Attachments
pi.pops.php.zip  (File Size: 2KB - Downloads: 197)
Profile
 
 
Posted: 27 August 2007 09:14 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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?

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 09:33 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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?

Profile
 
 
Posted: 27 August 2007 10:19 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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. smile

- 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:<br />
<
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:<br />
{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?

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 10:35 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 10:45 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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.

Profile
 
 
Posted: 27 August 2007 10:45 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
Posted: 27 August 2007 11:03 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

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.

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 27 August 2007 02:04 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

File Attachments
pi.pops.php.zip  (File Size: 2KB - Downloads: 153)
Profile
 
 
Posted: 27 August 2007 02:23 PM   [ Ignore ]   [ # 12 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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.

File Attachments
pi.pops.php 2.zip  (File Size: 3KB - Downloads: 244)
Profile
 
 
Posted: 28 August 2007 05:51 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

It works perfectly now! How can I thank you?

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 28 August 2007 07:28 AM   [ Ignore ]   [ # 14 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

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

Profile
 
 
Posted: 28 August 2007 07:37 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  170
Joined  04-08-2004

Well, a big woohoo for you excaim

Oh, and just in case anybody else on a similar quest finds this thread, displaying single custom fields in the preview is also easy:

{exp:pops:pop_input field=“fieldname”}{value}{/exp:pops:pop_input}

Thanks again, Phoebe!

 Signature 

~ I wish I could fix warp engines with duct tape & a pocket knife. ~

Profile
 
 
Posted: 19 September 2007 10:01 AM   [ Ignore ]   [ # 16 ]  
Lab Assistant
RankRank
Total Posts:  134
Joined  08-22-2007

Thank you Phoebe!!  I just found this thread and it has made my life much easier!! The plugin is excellent!  A world of thanks!

Profile
 
 
Posted: 11 March 2008 12:39 AM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

Great plugin! This should be featured on the Wiki I tell ya!

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 14 March 2008 12:42 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  160
Joined  06-24-2007

OMG you just made my night about 2 hours shorter THANK YOU

 Signature 

Web Inception
Websites that work for you.
http://www.webinception.com

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65027 Total Logged-in Users: 43
Total Topics: 82116 Total Anonymous Users: 24
Total Replies: 441313 Total Guests: 204
Total Posts: 523429    
Members ( View Memberlist )