How to put drop down list into array using codeigniter - codeigniter

I use the ion auth for codeigniter and it works great except that I don't know how to code drop down list the same way as the text field.
If you want to display a text field under view you have to issue this:
<?php echo form_input($first_name);?>
And this is the code under controller:
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'size' => 32,
'maxlength' => 32,
'value' => $this->form_validation->set_value('first_name'),
);
But how can I put the value of my drop down list into an array?
I tried putting this code under view:
<?php
$options = array(
'' => 'Select',
'Dr' => 'Dr.',
'Mr' => 'Mr.',
'Mrs' => 'Mrs.',
'Ms' => 'Ms.',
'Prof' => 'Prof.',
'Mr. & Mrs.' => 'Mr. & Mrs.',
);
echo form_dropdown('title', $options, '$title');
?>
I am thinking that under view I should code it like: echo form_dropdown($title); the same as text field but what is the code under controller?

First in your controller you can do :
$options = array(
'0' => 'Select',
'Dr' => 'Dr.',
'Mr' => 'Mr.',
'Mrs' => 'Mrs.',
'Ms' => 'Ms.',
'Prof' => 'Prof.',
'Mr. & Mrs.' => 'Mr. & Mrs.',
);
$data['options'] = $options
$this->load->view('your_view',$data);
In the View :
echo form_dropdown('title', $options, set_value('title'));
Moreover think you want to retain the value of the dropdown if a form validation error occurs:
you just need to put some validation to retain the values of the dropdown , somethin like:
$this->form_validation->set_rules('title','Titles','alpha');
If not validatted the dropdown will not retain the values in spite of using set_value

Related

Preview image in ACF gutenberg block

Is it possible to add an image to the gutenber block preview when using ACF to register the block ?
Here's the code to register the block:
acf_register_block(array(
'name' => 'bk-raisons',
'title' => __('Les raisons', 'diezel'),
'description' => __('Les raisons', 'diezel'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'spira-custom',
'icon' => 'align-wide',
'keywords' => array('bk-raisons'),
));
The preview appears when hovering the block.
Thank you !
I finally found a solution.
I don't know if you use Twig (Timber) or not.
If not check this : https://stackoverflow.com/a/67846162/6696150
For my part with Timber
When you declared your block add example attributes :
$img_quadruple = array(
'name' => 'img-quadruple',
'title' => __('Quatre images'),
'title_for_render' => 'img-quadruple',
'description' => __(''),
'render_callback' => 'ccn_acf_block_render_callback',
'category' => 'imgs',
'icon' => '',
'mode' => 'edit',
'keywords' => array( 'quatre images' ),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'preview_image_help' => get_template_directory_uri().'/assets/img/preview/preview_img_quadruple.jpg',
),
)
)
);
And when your declared your callback :
function ccn_acf_block_render_callback( $block, $content = '', $is_preview = false ) {
$context = Timber::context();
// Store block values.
$context['block'] = $block;
// Store field values.
$context['fields'] = get_fields();
// back-end previews
if ( $is_preview && ! empty( $block['data'] ) ) {
echo '<img src="'. $block['data']['preview_image_help'] .'" style="width:100%; height:auto;">';
return;
} elseif ( $is_preview ) {
echo 'Other condition';
return;
}
// Store $is_preview value.
$context['is_preview'] = $is_preview;
// Render the block.
Timber::render('gutenberg/gut_' . strtolower($block['title_for_render']) . '.twig', $context );
}

How to add elements to a fieldset in magento horizontally rather than vertically

I am adding few check boxes in to magento using the fieldset option like the following.
$fieldset = $form->addFieldset('display', array(
'legend' => $helper->__('Schedule Sales Order Transfer'),
'class' => 'fieldset-wide'
));
for($i=01; $i*5<60; $i++){
$time = $i*5;
$fieldset->addField('min'.$time, 'checkbox', array(
'name' => 'Checkbox',
'checked' => false,
'onclick' => self::setAll("min"),
'onchange' => "",
'value' => ''.$time,
'disabled' => false,
'after_element_html' => '<small>'.$time.'</small>',
'tabindex' => 1
));
}
By doing so, all the check boxes are coming one below another. Is it possible to make it one adjacent to another i.e., horizontally?
Anybody Please suggest the solution ASAP...
Thank you,
In your Code return like <tr>...</tr><tr>..</tr>, so if you need to add custom css or js to achieve what you expected,
or
for($i=01; $i*5<60; $i++){
$time[$i]['value'] = $i*5;
$time[$i]['label'] = $i*5;
}
$fieldset->addField('Time', 'checkboxes', array(
'label' => $this->__('Time'),
'name' => 'time[]',
'values' => $time,
'value' => '1',
'tabindex' => 1
));
its return like <tr><td>label</td><td>value<ul><li></li>....<li></li></ul></td></tr>
then you continue your stuff.,
Note: I'm just suggest the possible ways

How do I create a configurable product with associated products?

The following code does create a configurable product, however, when I open the product in the backend, the following message appears:
Select Configurable Attributes
"Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available."
A single checkbox is displayed ("Colour Group"), which must be selected before continuing.
When I click "Continue", all of the product data is there as expected EXCEPT for the associated products.
//Mage Product
$mpr = Mage::getModel('catalog/product');
$mpr
->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
->setTaxClassId(5)
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->setWebsiteIds(array(1))
->setAttributeSetId(4) // You can determine this another way if you need to.
->setSku("C12345")
->setName("C12345")
->setQty(25)
->setShortDescription('short description')
->setDescription('description')
->setPrice(1)
->setStockData(array(
'use_config_manage_stock' => 1,
'is_in_stock' => 1,
'is_salable' => 1,
));
$productData = array(
'7039604' =>
array('0' => array('attribute_id' => '85', 'label' => 'ROYAL','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => '')
,'1' => array('attribute_id' => '192', 'label' => '14', 'value_index' => '28728', 'is_percent' => 0, 'pricing_value' => '')
)
);
$attributeData = array(
'0' => array(
'id' => NULL
,'label' => 'Color'
,'position' => NULL
,'values' => array(
'0' => array('value_index' => 28563, 'label' => 'ROYAL', 'is_percent' => 0, 'pricing_value' => '0', 'attribute_id' => '85')
)
,'attribute_id' => 85
,'attribute_code' => 'color'
,'frontend_label' => 'Color'
,'html_id' => 'config_super_product__attribute_0')
,'1' => array(
'id' => NULL
,'label' => 'Rivers Size'
,'position' => NULL
,'values' => array(
'0' => array('value_index' => 28728, 'label' => '14', 'is_percent' => 0, 'pricing_value' => '0', 'attribute_id' => '192')
)
,'attribute_id' => 192
,'attribute_code' => 'rivers_size'
,'frontend_label' => 'Rivers Size'
,'html_id' => 'config_super_product__attribute_1')
);
$mpr->setConfigurableProductsData($productData);
$mpr->setConfigurableAttributesData($attributeData);
$mpr->setCanSaveConfigurableAttributes(true);
$mpr->save();
Add this code before $mpr->save();
$SKU = "any-simple product sku enter here";
$productid = Mage::getModel('catalog/product')
->getIdBySku(trim($SKU));
$mpr->assignProduct($productid);
And set simple product sku in $SKU variable. and i have check that when i select global variable then after i see associated product in configure product.
Its work fine !!!
If you are getting redirected to select attribute page, this means that attribute data you set in this sample is not saved correctly.
Try viewing catalog_product_super_attribute after script run (new rows should be added).

CakePHP 2 & Translate Behavior: save multiple translations in a single form

Its possibile save multiple translations of the same field in a single form?
I have a model with Behavior Translate to translate the name field. The three translations (deu, eng, ita) are properly recorded in the i18n table but the field is not properly validated! Any suggestions?
app/Model/Category.php
class Category extends AppModel {
public $actsAs = array('Translate' => array('name' => 'TranslateName'));
public $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Error notempty',
),
),
);
...
app/View/Categories/admin_edit.ctp
<?php
echo $this->Form->create('Category');
echo $this->Form->input('Category.id');
echo $this->Form->input('Category.name.deu', array('label' => __d('Category', 'Name Deu')));
echo $this->Form->input('Category.name.eng', array('label' => __d('Category', 'Name Eng')));
echo $this->Form->input('Category.name.ita', array('label' => __d('Category', 'Name Ita')));
echo $this->Form->end(__d('app', 'Submit'));
?>
app/View/Controller/CategoriesController.php
if ($this->Category->save($this->request->data)) {
$this->Session->setFlash(__d('Category', 'The category has been saved'));
} else {
$this->Session->setFlash(__d('Category', 'The category could not be saved. Please, try again.'));
}
I have a similar Problem
But you can try out this - it should solve it for you: https://github.com/zoghal/cakephp-MultiTranslateBehavior

Adding class to form_dropdown in CodeIgniter

How do I add a class to a form_dropdown in CodeIgniter if I also have a Javascript attached. Here is my code:
$language = array(
'select' => 'Select Language',
'chinese' => '中文',
'english' => 'English',
'french' => 'Français',
'german' => 'Deutsch',
'italian' => 'Italiano',
'japanese' => '日本',
'korean' => '한국어',
'polish' => 'Polska',
'portuguese' => 'Português',
'russian' => 'Росс&#1048Ю',
'spanish' => 'Español'
);
$js = 'onChange="this.form.submit()"';
echo form_dropdown('language', $language, 'select', $js);
Add the class to the $js variable;
$js = 'onChange="this.form.submit()" class="myClass"';

Resources