...
Code Block |
---|
$this->fields_form = array( 'legend' => array( 'title' => $this->l('Edit carrier'), // This is the name of the fieldset, which can contain many option fields 'image' => '../img/admin/icon_to_display.gif' // The icon must, if there is one, must be of the size 16*16 ), 'input' => array( array( 'type' => {'text', 'select', 'textarea', 'radio', 'checkbox', 'file', 'shop', 'asso_shop', 'free', 'color'}, ['label'] => $this->l('Shipping method'), // Theoretically optional, but in reality each field has to have a label 'name' => 'shipping_method', // The name of the object property from which we get the value ['required'] => {true, false}, // If true, PrestaShop will add a red star next to the field ['desc'] => $this->l('Description displayed under the field.'), ['hint'] => $this->l('Invalid characters:').' <>;=#{}' // This is displayed when the mouse hovers the field. ['suffix'] => 'kg' // This is displayed after the field (ie. to indicate the unit of measure) ['options'] => array( // This is only useful if type == select 'query' => $array_of_rows, // $array_of_rows must contain an array of arrays, inner arrays (rows) being mode of many fields 'id' => 'id_carrier', // The key that will be used for each option "value" attribute ), ['values'] => array( // This is only useful if type == radio array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), [is_bool] => {true, false}, // This is only useful if type == radio. It displays a "yes or no" choice. ['empty_message'] => $this->l('To be displayed when the field is empty.'), ['lang'] => {true, false}, // Is the field multilang? ), array( //another field ), ), 'submit' => array( 'title' => $this->l(' Save '), // This is the button that saves the whole fieldset. 'class' => 'buttonbtn btn-default pull-right' ) ); |
Note |
---|
If you want to use the "color" type, you can add the |
...
Code Block |
---|
$this->fields_form = array( 'legend' => array( 'title' => $this->l('Edit carrier'), 'image' => '../img/admin/icon_to_display.gif' ), 'input' => array( array( 'type' => 'text', 'name' => 'shipping_method', ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'buttonbtn btn-default pull-right' ) ); |
This specific code generates this HTML code (simplified here for readability reasons):
Code Block |
---|
<form id="_form"> <fieldset id="fieldset_main_conf"> <legend> <img alt="Edit carrier" src="../img/admin/icon_to_display.gif">Edit carrier </legend> <div class="margin-form"> <input type="text" class="" value="" id="shipping_method" name="shipping_method"> </div> <div class="clear"></div> <div class="margin-form"> <input type="submit" class="buttonbtn btn-default pull-right" name="" value="Save" id="_form_submit_btn"> </div> </fieldset> </form> |
...
Code Block | ||
---|---|---|
| ||
array( 'type' => 'text', // This is a regular <input> tag. 'label' => $this->l('Name'), // The <label> for this <input> tag. 'name' => 'name', // The content of the 'id' attribute of the <input> tag. 'sizeclass' => 50'lg', // The content of the 'sizeclass' attribute of the <input> tag. To set the size of the element, use these: sm, md, lg, xl, or xxl. 'required' => true, // If set to true, this option must be set. 'desc' => $this->l('Please enter your name.') // A help text, displayed right next to the <input> tag. ), |
The 'size' attribute has been deprecated in v1.6: use 'class' instead.
Selector
Here is how to generate a <select>
element:
...