Carrington Build Documentation

The Admin Form

The admin_form() method is used to collect user settings and content for each module. The admin_form() method must return HTML. The module admin form only needs to contain the form fields you need to collect. Do not include the form tags as those are automatically added to the output.

class my_build_module extends cfct_build_module {

	// ...

	public function admin_form($data) {
		$title = (isset($data[$this->get_field_name('title')]) ? $data[$this->get_field_name('title')] : null);
		$content = (isset($data[$this->get_field_name('content')]) ? $data[$this->get_field_name('content')] : null);
		$html = '
			<fieldset>
				<div>
					<input type="text" name="'.$this->get_field_name('title').'" id="'.$this->get_field_id('title').'" value="'.esc_html($title).'" />
				</div>
				<div>
					<textarea name="'.$this->get_field_name('content').'" id="'.$this->get_field_id('content').'">'.htmlentities($content).'</textarea>
				</div>
			</fieldset>';

		return $html;
	}

	// ...
}

 

Like WordPress Widgets there are helper methods to help keep your field names and IDs name-spaced. The following is an example of a basic admin interface that gathers title and content data from the user:

Any fields included in the admin for that are not disabled (ie: disabled=”disabled”) will be submitted and passed through the update() method before being saved. If there are auxillary fields in the markup that shouldn’t be saved in to the database or if some data transformations should be done use the update() method to modify $data before it is saved. For example:

class my_build_module extends cfct_build_module {

	// ...

	public function update($new_data, $old_data) {
		if (!empty($data[$this->get_field_name('foo')])) {
			$data[$this->get_field_name('bar')] += ' '.$data[$this->get_field_name('foo')];
			unset($data[$this->get_field_name('foo')]);
		}
		return $data;
	}

	// ...
}

See also:

Back to Carrington Build

These sections are available to the public. The remaining sections are available exclusively to customers.