<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Custom_field_ft extends EE_Fieldtype {
var $info = array(
'name' => 'Custom Field',
'version' => '1.0'
);
function display_field($data) {
return form_input(array(
'name' => $this->field_name,
'id' => $this->field_id,
'value' => $data
));
}
}
function display_field($data)
{
return "Custom Field";
}
public function accepts_content_type($name)
{
return ($name == 'channel' || $name == 'grid' || $name == 'fluid_field');
}
function validate($data)
{
if (preg_match('/^#[a-f0-9]{6}$/i', $data)) {
return true;
} else {
return "Value contains only characters or numbers";
}
}
public function save($data)
{
return $data;
}
function replace_tag($data, $params = array(), $tagdata = FALSE)
{
return "Prefix " . $data . " Suffix";
}
function display_settings() {
$settings = array(
array(
'title' => 'Max Length',
'desc' => 'max_length_desc',
'fields' => array(
'max_length' => array(
'type' => 'text',
'value' => '10',
)
)
),
// ... you can define more fields here ...
);
return array(
'field_options_custom_field' => array(
'label' => 'field_options',
'group' => 'custom_field',
'settings' => $settings
)
);
}
public function save_settings($data)
{
// do the stuff with $data
return $data;
}
Conclusion
In the end, you have learned how to develop a Fieldtype in ExpressionEngine. In the above content, we explained only the basics of creating a Field Type with standard functions that are mostly used in any Field Type—Saving and validation of the data of field type and field settings.