-
Notifications
You must be signed in to change notification settings - Fork 0
Plugin Form Sample
Justin Campo edited this page Oct 24, 2015
·
1 revision
$c->form->init(array("action" => "/account/edit/", "title" => "Edit Account", "submit" => "Save Changes"));
$items = array();
$items[] = array("type" => "text", "label" => "First Name", "value" => $c->account->item->first_name, "validation" => array("required" => true));
$items[] = array("type" => "text", "label" => "Last Name", "value" => $c->account->item->last_name, "validation" => array("required" => true));
$items[] = array("type" => "text", "label" => "Email", "value" => $c->account->item->email, "validation" => array("email" => true));
$c->form->items($items, $c);
if (isset($c->wine->item->id) AND $c->wine->item->id != 0){
$c->form->init(array("action" => "/wine/edit/", "title" => "Edit Wine", "submit" => "Save Changes"));
} else {
$c->form->init(array("action" => "/wine/edit/", "title" => "New Wine", "submit" => "Create New Wine")); //, "debug" => true
}
$i = 0;
$items[$i] = array("type" => "hidden", "name" => "id", "value" => $c->wine->item->id);
$i++;
$items[$i] = array(
"type" => "text",
"label" => "Start With Existing Wine",
"help" => "Fill in fields with data from existing wine",
"content" => "<button class='button' type='button'>Load Data</button>"
);
/**
$(function() {
var cache = {};
$( "#birds" ).autocomplete({
minLength: 2,
source: function( request, response ) {
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
$.getJSON( "search.php", request, function( data, status, xhr ) {
cache[ term ] = data;
response( data );
});
}
});
});
***/
$i++;
$option = array();
$option[] = array("name" => "Select Year", "value" => "");
$year = date("Y");
while ($year > 1750){
if ($c->wine->item->vintage == $year ){
$option[] = array("name" => $year, "selected" => true);
} else {
$option[] = array("name" => $year);
}
$year--;
}
$items[$i] = array("type" => "select", "label" => "Vintage", "validation" => array("required" => true), "option" => $option);
$i++;
$items[$i] = array("type" => "text", "label" => "Name", "value" => $c->wine->item->name, "validation" => array("required" => true));
$i++;
$type_list = $c->wine->query("type");
if (count($type_list)){
$option = array();
$option[] = array("name" => "Select Type", "value" => "");
foreach ($type_list as $type){
if ($c->wine->item->type == $type ){
$option[] = array("value" => $type["id"], "name" => $type["label"], "selected" => true);
} else {
$option[] = array("value" => $type["id"], "name" => $type["label"]);
}
}
}
$items[$i] = array("type" => "select", "label" => "Type", "option" => $option, "validation" => array("required" => true));
$i++;
$style_list = $c->wine->query("style");
if (count($style_list)){
$option = array();
foreach ($style_list as $style){
if (in_array($style,$c->wine->item->style)){
$option[] = array("value" => $style["id"], "label" => $style["label"], "selected" => true);
} else {
$option[] = array("value" => $style["id"], "label" => $style["label"]);
}
}
}
$items[$i] = array("type" => "checkbox", "label" => "Style", "option" => $option);
$i++;
$grape_list = $c->wine->query("grape");
if (count($grape_list)){
$option = array();
$option[] = array("name" => "Select Type", "value" => "");
foreach ($grape_list as $grape){
if (in_array($grape,$c->wine->item->grape)){
$option[] = array("value" => $grape["id"], "name" => $grape["label"], "selected" => true);
} else {
$option[] = array("value" => $grape["id"], "name" => $grape["label"]);
}
}
}
$expand = array("label" => "[Add Another Grape]", "type" => "click", "max" => 4);
$swap = array("label" => "[Add New Grape]", "type" => "text");
$items[$i] = array("type" => "select", "label" => "Grapes", "option" => $option, "expand" => $expand, "swap" => $swap, "help" => "test");
$this->data["js"][] = "jquery-combobox.min.js";
$grape_counter = 0;
while ($grape_counter < $expand["max"]){
$this->data["script"][] = '$("#grapes'.$grape_counter.'").combobox();';
$grape_counter++;
}
$i++;
$items[$i] = array("type" => "text", "label" => "Producer", "value" => $c->wine->item->producer);
$i++;
$items[$i] = array("type" => "text", "label" => "Vineyard", "value" => $c->wine->item->vineyard);
$i++;
$option = array();
$size_list = $c->wine->query("size");
if (count($size_list)){
foreach ($size_list as $size){
if (in_array($size,$c->wine->item->size)){
$option[] = array("value" => $size["ml"], "label" => $size["label"], "selected" => true);
} else {
$option[] = array("value" => $size["ml"], "label" => $size["label"]);
}
}
}
$items[$i] = array("type" => "checkbox", "label" => "Size", "option" => $option);
$i++;
$option = array();
$option[] = array("name" => "Select Country", "value" => "");
$country_list = $c->wine->query("country");
if (count($country_list)){
foreach ($country_list as $country){
if ($c->wine->item->country == $country){
$option[] = array("value" => $country["code"], "name" => $country["label"], "selected" => true);
} else {
$option[] = array("value" => $country["code"], "name" => $country["label"]);
}
}
}
$items[$i] = array("type" => "select", "label" => "Country", "option" => $option);
$i++;
$items[$i] = array("type" => "text", "label" => "Region", "value" => $c->wine->item->region);
$i++;
$items[$i] = array("type" => "text", "label" => "Appellation", "value" => $c->wine->item->appellation);
$i++;
$items[$i] = array("type" => "text", "label" => "Alcohol", "value" => $c->wine->item->alcohol);
//select dropdown 22-0 percent
$i++;
$items[$i] = array("type" => "text", "label" => "PH", "value" => $c->wine->item->ph);
//0 to 14
$i++;
$items[$i] = array("type" => "text", "label" => "Residual Sugar", "value" => $c->wine->item->residual_sugar);
//0 to 1000
$i++;
$items[$i] = array("type" => "text", "label" => "Brix", "value" => $c->wine->item->brix);
//18-32
$i++;
$items[$i] = array("type" => "text", "label" => "Cooperage", "value" => $c->wine->item->cooperage);
$i++;
$items[$i] = array("type" => "text", "label" => "Harvest Date", "value" => $c->wine->item->harvest, "validation" => array("date" => true));
$this->data["script"][] = '$("#harvestdate").datepicker();';
$i++;
$items[$i] = array("type" => "text", "label" => "Bottled Date", "value" => $c->wine->item->release, "validation" => array("date" => true));
$this->data["script"][] = '$("#bottleddate").datepicker();';
$i++;
$items[$i] = array("type" => "text", "label" => "Release Date", "value" => $c->wine->item->bottled, "validation" => array("date" => true));
$this->data["script"][] = '$("#releasedate").datepicker();';
$i++;
$items[$i] = array("type" => "text", "label" => "GTIN", "value" => $c->wine->item->gtin);
$i++;
$items[$i] = array("type" => "text", "label" => "UPC", "value" => $c->wine->item->upc);
$i++;
$items[$i] = array("type" => "text", "label" => "AVIN", "value" => $c->wine->item->avin);
$i++;
$expand = array("label" => "[Add Another Price]", "type" => "click", "max" => 6);
$items[$i] = array("type" => "text", "label" => "Price", "value" => $c->wine->item->avin, "help" => "US Dollar Format [ie. $1000.00]","expand" => $expand, "validation" => array("price" => true));
//Prices
$i++;
$expand = array("label" => "[Add Another Image]", "type" => "click", "max" => 6);
$items[$i] = array("type" => "file", "label" => "Image", "value" => $c->wine->item->avin, "expand" => $expand);
//image upload system
$c->form->items($items, $c);