Variable-Length Line Item Edits: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
Line 39: Line 39:
==Collecting form data==
==Collecting form data==


Parent content class doesn't require any form data collection.
Parent content class doesn't require any form data collection for the line item data.


==Validating form data==
==Validating form data==

Revision as of 18:00, 28 July 2012

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 anchor or button element 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 for the line item data.

Validating form data

Parent class doesn't require any form data validation for the line item data.

Examples