Variable-Length Line Item Edits
Overview
Describes how to add modules to CMS edit pages where variable-length arrays of objects can be added to a content record.
Markup
Edit form
Simple include directive to insert entire module into the edit form.
include (SECTION_BASE_DIR."_templates/forms/[CONTENT_DESCRIPTION]_container.php");
Module container include
- Header followed by an
anchororbuttonelement to be used as button to add new line items. - Error container for AJAX errors specific to this module.
div element to serve as container for the line items.class="form-section"to contain the listings and control their position within the flow of the page.- And addition attribute to be used to reference the container and update its contents. E.g.
class="related-products"
- Test for array of line item objects and test for its size.
- Iteration through array, inserting static content for each existing line item along with buttons to edit and delete the line items, depending on the circumstances.
<div class="line-item-module">
<h3>[CONTENT_LABEL] <button class="add-[CONTENT_CODE]-btn" title="add [CONTENT_LABEL]">add [CONTENT_LABEL]</button></h3>
<div id="[CONTENT_CODE]-error-container" class="error"><!-- --></div>
<div class="form-section [CONTENT_CODE]-container">
<?
if (isset($input->[CONTENT_CODE]_array) && is_array($input->[CONTENT_CODE]_array) && count($input->[CONTENT_CODE]_array)>0):
foreach ($input->[CONTENT_CODE]_array as &$rp):
include (CONTENT_BASE_DIR."_templates/forms/[CONTENT_CODE]_line.php");
endforeach;
else: ?>
<div class="no-results"><i>No [CONTENT_LABEL] have been added.</i></div>
<? endif; ?>
</div>
</div>PHP
Collecting form data
Parent content class doesn't require any form data collection.
Examples