Thanks Brian. I can’t seem to get the values to display in the edit form. Here is what I have for the ENTRY form, which works fine:
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" value="Public" />Public
<input type="checkbox" name="field_id_350[]" value="Practitioners" />Practitioners
<input type="checkbox" name="field_id_350[]" value="Trainees" />Trainees
The EDIT version doesn’t work. I’ve tried:
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" id="public" value="field_id_350[]" />Public
<input type="checkbox" name="field_id_350[]" id="practitioners" value="field_id_350[]" />Practitioners
<input type="checkbox" name="field_id_350[]" id="trainees" value="field_id_350[]" />Trainees
and
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" id="public" value="Public" {checked} />Public
<input type="checkbox" name="field_id_350[]" id="practitioners" value="Practitioners" {checked} />Practitioners
<input type="checkbox" name="field_id_350[]" id="trainees" value="Trainees" {checked} />Trainees
and
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" id="field_id_350[]" value="field_id_350[]" {checked} />Public
<input type="checkbox" name="field_id_350[]" id="field_id_350[]" value="field_id_350[]" {checked} />Practitioners
<input type="checkbox" name="field_id_350[]" id="field_id_350[]" value="field_id_350[]" {checked} />Trainees
In each case, all checkboxes in the EDIT form are blank.
Any help?
Thanks again, Ken
Ken - you’ll need to use SolSpace’s Form Helper plugin, and then you’ll end up with code like so for your values:
value="{exp:form_helper:field_parser}{field_id_40}{/exp:form_helper:field_parser}"
EDIT: or you can do it using PHP and the $DB class if you prefer…
Brian, your quick responses are much appreciated! A couple more samples of code I’ve tried that are not working:
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_parser}{field_id_350}{/exp:form_helper:field_parser}" />Public
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_parser}{field_id_350}{/exp:form_helper:field_parser}" />Practitioners
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_parser}{field_id_350}{/exp:form_helper:field_parser}" />Trainees
and this one, after reading the form helper docs again, using field_grabber instead of field_parser, since my understanding is that the field_parser is to remove or grab the formatting (XHTML, BR or None), and the checkbox does not have field formatting:
<b>Open to</b>
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_grabber field_name='field_id_350'} value="{field_id_350}" />Public
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_grabber field_name='field_id_350'} value="{field_id_350}" />Practitioners
<input type="checkbox" name="field_id_350[]" value="{exp:form_helper:field_grabber field_name='field_id_350'} value="{field_id_350}" />Trainees
I also tried a version of the above with both field_grabber and field_parser, per the Solspace docs, with no luck.
(I don’t have the coding experience to try the PHP and $DB class method you mentioned) :red:
I just realized I’m using PHP to do it in my templates (using Field Helper for other forms not using checkboxes). I’m not sure if this will work, but try this:
<input type="checkbox" name="field_id_350[]" value="Public" {exp:form_helper:field_parser}{if field_id_350 == 'Public'} checked="checked"{/if}{/exp:form_helper:field_parser} />Public
If that doesn’t work I’ll help you set it up using PHP.
Hi Mark,
Apologies for the delay getting back. I’ve been occupied with another project.
I tried the code you sent above… still didn’t work.
I’m thinking I should rethink the way we’re setting this up, but I’m interested in seeing how you would do it with PHP as well.
Thanks for all the help, Ken
Hi all, I’m not sure that I’m using this properly…
I’m hoping to provide 6 checkboxes in the publish form in a custom field called {stockists-offers}
The options are:
Fabrics Wallpapers Paints Paint-Sample-Pots Trimmings Furniture
I want a list item containing an icon to appear IF the box has been ticked so I produced this code, it seems to work for Fabrics (the first item) but nothing else :(
<ul class="offers">
{if stockist-offers == "Fabrics"}<li class="fabric-icon">Fabrics</li>{/if}
{if stockist-offers == "Wallpapers"}<li class="wallpaper-icon">Wallpapers</li>{/if}
{if stockist-offers == "Paints"}<li class="paint-icon">Paints</li>{/if}
{if stockist-offers == "Paint-Sample-Pots"}<li class="sample-icon">Paint Sample Pots</li>{/if}
{if stockist-offers == "Trimmings"}<li class="trimmings-icon">Trimmings</li>{/if}
{if stockist-offers == "Furniture"}<li class="furniture-icon">Furniture</li>{/if}
</ul>
That’s because in the database it’s stored as:
Fabrics
Wallpapers
So if you select more than one item it won’t work because “Wallpapers != Fabrics\nWallpapers”
You could use PHP on output to get around this:
<?php
$stocklist_offers = <<<EOT
{stocklist-offers}
EOT;
?>
<ul class="offers">
<?php if(strpos($stockist_offers, "Fabrics")): ?><li class="fabric-icon">Fabrics</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Wallpapers")): ?><li class="wallpaper-icon">Wallpapers</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Paints")): ?><li class="paint-icon">Paints</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Paint-Sample-Pots")): ?><li class="sample-icon">Paint Sample Pots</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Trimmings")): ?><li class="trimmings-icon">Trimmings</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Furniture")): ?><li class="furniture-icon">Furniture</li><?php endif; ?>
</ul>
That’s sort of off the top of my head so there may be a syntax error in there or a typo, but it should get you started
Thanks Mark, I think there may be an error somewhere as the page is coming up blank. Unfortunately I don’t know any php so I’m stumped as what the problem could be :/
Here is most of the page code if you can see anything quickly wrong with it?
<div id="content">
<h2>{page}</h2>
<h3 id="sub-heading">{countries}</h3>
{exp:weblog:category_heading weblog="{section}"}
<h4>{category_name}</h4>
{/exp:weblog:category_heading}
<ol id="stockistslist">
{exp:weblog:entries weblog="stockists_{segment_3}" paginate="bottom" limit="9"}
<li>
<dl>
<dt>{title}</dt>
<dd>{stockist-address}</dd>
<dd><strong>Tel: </strong>{stockist-phone}</dd>
<dd><strong>Fax: </strong>{stockist-fax}</dd>
<dd><strong>Email: </strong>{stockist-email}</dd>
<dd><strong>Website: </strong>{if stockist-website}<a href="http://{exp:html_strip}{stockist-website}{/exp:html_strip}" title="Visit {title}'s website">Click here</a> {if:else} N/A{/if}</dd>
<dd><strong>Map and Directions: </strong><a href="#">Click here</a></dd>
<dd>
<?php
$stocklist_offers = <<<EOT
{stocklist-offers}
EOT;?>
<ul class="offers">
<?php if(strpos($stockist_offers, "Fabrics")): ?><li class="fabric-icon">Fabrics</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Wallpapers")): ?><li class="wallpaper-icon">Wallpapers</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Paints")): ?><li class="paint-icon">Paints</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Paint-Sample-Pots")): ?><li class="sample-icon">Paint Sample Pots</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Trimmings")): ?><li class="trimmings-icon">Trimmings</li><?php endif; ?>
<?php if(strpos($stockist_offers, "Furniture")): ?><li class="furniture-icon">Furniture</li><?php endif; ?>
</ul>
</dd>
</dl>
</li>
{/exp:weblog:entries}
</ol>
</div><!-- content -->
</div><!-- wrapper -->
{embed="includes/footer"}
A couple of reasons, I had and error in my heredoc syntax (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) and you need to make sure that the EOT;
is the only thing on the line, meaning no spaces before it.
This should work:
<?php
$stocklist_offers = <<<EOT
{stocklist-offers}
EOT;
?>
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.