Views
form.php and display.php
This is section 2 of the PyroCMS widget creation example. As stated before, PCMS is built upon Codeigniter – a very powerful and easy to learn PHP Framework. Codeigniter is MVC compliant.
You have updated the class file – affiliate.php. In there, you defined the fields you will use in the admin interface to actually add the content for your affiliate link widget.
Download the affiliate.zip file here
Next, we edit the files contained in the ‘views’ sub-folder. There will be two – ‘display.php’ and ‘form.php’. They do exactly what they say they will do – display the content of the widget and create the form interface to add your content to the widget.
NOTE: I have kept the CSS and JavaScript in the files to ease the understanding of the PyroCMS widget creation. This is not standard practice, but lets not add confusion to what may be a challenging topic by rigorously adhering to coding standards purity during the learning phase.
form.php
<?php
/**
* form.php for affiliate widget
* ==============================
* @author Victor Russell - www.randaweb.com
*
* Create the form using Codeigniter form_helper and form_validation libraries
* form_input() and form_textarea() are used to display the content from the
* database.
*
**/
?>
<ol>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Title (used for onhover - tooltips)</label>
<?php echo form_input(array('name'=>'aff_title', 'value' => $options['aff_title'] ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Row Break - 1 = new line/row</label>
<?php echo form_input(array('name'=>'aff_order', 'value' => $options['aff_order'],
'size' => '3', 'maxlength' => '3' ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Link <a> *</label>
<?php echo form_textarea(array('name'=>'aff_link', 'value' => $options['aff_link'], 'rows' => '5' ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Alt Text</label>
<?php echo form_input(array('name'=>'aff_alt', 'value' => $options['aff_alt'] ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate CSS Class</label>
<?php echo form_input(array('name'=>'aff_class', 'value' => $options['aff_class'] ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate CSS Style</label>
<?php echo form_textarea(array('name'=>'aff_style', 'value' => $options['aff_style'], 'rows' => '2' ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate Source (CJ, ClickBank...) *</label>
<?php echo form_input(array('name'=>'aff_source', 'value' => $options['aff_source'] ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Ad Company *</label>
<?php echo form_input(array('name'=>'aff_company', 'value' => $options['aff_company'] ) ); ?>
</li>
</ol>
<?php //echo js('codemirror/codemirror.js'); ?>
<?php /*<script type="text/javascript" defer="defer">
html_editor('html_editor', "25em");
</script> */
?>
The form.php is rather simple. The main hurdle you may have is the syntax used to create the form elements – this is Codeigniter’s style and is very powerful. Once you really understand it, it is very simple.
Link to the very excellent Codeigniter documentation. Click on the drop-down menu at the very top of the page and examine all of the classes, helpers, libraries, and other useful information.

Codeigniter form helper and form validation documentation
<label>Affiliate Source (CJ, ClickBank...) *</label>
<?php echo form_input(array('name'=>'aff_source', 'value' => $options['aff_source'] ) ); ?>
This code creates a form element label and the CI method of a input type=’text’ element.
The form_input() method creates the following (using ‘view generated source’ after rendering the page with an affiliate widget):
<input type="text" name="aff_title" value="">
The Codeigniter form validation class then checks the length of the fields, as well as other attributes (numeric, alphanumeric, integer, etc), against the array that you created in the ‘affiliate.php’ file. If an error occurs, you will get a detailed error message near the top of the widget container telling you the field and error. This occurs after you click ‘Save’.
For the PHP Codeigniter form_textarea() method,
<?php echo form_textarea(array('name'=>'aff_style', 'value' => $options['aff_style'], 'rows' => '2' ) ); ?>
the resulting form element looks like this:
<textarea name="aff_link" cols="90" rows="5" value=""></textarea>
The one very important and simplification from standard form handling is the ‘value’ => $options['aff_style'] attribute. If there is content in the field, this array value is assigned as the value of the form element, displaying it for viewing and editing.

Widget Form Preview
Affiliate Links
Because of the issue regarding Javascript inclusion in text areas and input fields, use only HTML-formated affiliate links from your provider (ClickBank, Commission Junction, etc). Do not add any features that some providers have as options – such as CJ’s ‘Hide tracking code in link?’ and ‘Encrypt link?’ options – don’t use them or your links won’t work as expected.
Future
I am working on an automated affiliate link manager for PyroCMS – this will be a ‘module’ and not a ‘widget’. This will allow you to program your site to populate a link section or sections with specific categories using your link providers API.
Thanks,
Vic Russell
Russell and Associates
www.randaweb.com/forum
randaweb@gmail.com