how to modify <select required> to form_dropdown in codeigniter - php

according to the question asked by Outliers here, and according to the answer posted by Adr
echo form_dropdown('salutation', $salutationOptions, '', 'required="required"');
i've tried similar line of code when creating form_dropdown in controller of code igniter, i do it like this
$code = array(
'type' => 'text',
'id' => 'productcode',
'name' => 'productcode',
'class' => 'form-control',
'required'=> 'required'
);
$form['open'] = form_open_multipart('Mould/saveeditproduct');
$form['code'] = form_input($code);
$form['category'] = form_dropdown('category',$category,'','id="category" class="form-control" required="required"');
$form['submit'] = form_input($submit);
$form['close'] = form_close();
i try to run the program, i found that the 'required' property is worked well in form_input, but does not work in form_dropdown. so, how can i fix this? thank you

The problem was that you assigned a value for first option in dropdown (----- Select Category -----) as 0
Try this code:
// $data['category'] = array( array('idcategory' => 4,'categoryname' => 'new'),
// array('idcategory' => 2,'categoryname' => 'old'));
$data['category'] = $this->Mouldmodel->getallcategory();
$category[] = array();
$category[''] = '----- Select Category -----';
foreach($data['category'] as $dm){
$category[$dm['idcategory']] = $dm['categoryname'];
}

Related

always get The input was not found in the haystack in zf2 select element

I am new in zf2
I am always getting the error The input was not found in the haystack when I have select a language from a drop down. Here's my code:
In my controller
function singleAction(){
—
—-
—-
$language = array();
$languages = $this->getManageTable()->getLanguage();
foreach($languages as $lang){
$language[”] = ‘Select Language';
$language[$lang[‘id_language’]] = $lang[‘name’];
}
—
—-
—-
return new ViewModel(array(
‘form’ => $form,
‘language’ => $language,
));
}
Inside manageForm.php :
// Language Input
$language = new Element\Select(‘language’);
$language->setAttributes(array(
‘id’ => ‘language’,
‘class’ => ‘form-control’,
));
$this->add($language);
$language = new InputFilter\Input(‘language’);
$language->setRequired(false);
//$language->removeValidator(“NotEmpty”); // not working giving error
// not working giving error:
//$language->setAllowEmptysetRegisterInArrayValidator(false);
//$language->setErrorMessage(‘Please select language’);
$inputFilter->add($language);
In my View I called like so:
Language
<?php echo formSelect($form->get(‘language’)->setValueOptions($language)); ?>
Now when I submit without selecting value from drop-down working fine..
..but if I select some language and submit, I get this error The input was not found in the haystack.
I checked my language data I am getting in post but if ($form->isValid()) {—-} gives me an error.
How can I resolve this, I checked lot of links but haven't found any solutions. Please help me. I don't want to validate this drop-down element.
This works for me:
$this->add(
array(
'type'=> 'Zend\Form\Element\Select',
'name' => 'language',
'required' => true,
'attributes' => array(
'class' => 'form-control',
'value' => 'en' ,
),
'options' => array(
'disable_inarray_validator' => true,
)
));
oho Thanks God,
I got the solution
Inside manageForm.php :
$language = new Element\Select('language');
$language->setAttributes(array(
'id' => 'language',
'class' => 'form-control',
));
$language->setDisableInArrayValidator(true);
$this->add($language);
$language = new InputFilter\Input(‘language’);
$language->setRequired(false);
$language->setErrorMessage(‘Please select language’);
$inputFilter->add($language);
That it, it is now working fine. May be it will help someone.
Thank you

Zend2 Form - set attributes to options in select element

I wonder how to add some attributes to select's options in Zend 2. My form element looks like this:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'brand_name',
'options' => array(
'label' => 'Choose brand',
'value_options' => $this->getBrands(),
),
));
So it's populate select looking similar to this:
<select name="brand_name"><option value="1">aaaa</option></select>
But I want to achieve something like this:
<select name="brand_name"><option value="1" class="test">aaaa</option></select>
And the classes should be different, depends on particular option. Is it possible? Why am I trying this? I need to add jquery plugin - chained which needs classes for options.
I've found a solution, array of parent select value_options should look like this:
foreach ($data as $item) {
$models[] = array(
'label' => $item->model_name,
'attributes' => array('class' => $item->id_brand_list),
'value' => $item->id);
}
If your data were array that you preferred getting from sql or db, you can code like:
public function getOptionsForDataSelect()
{
$dbAdapter = $this->_adapter;
$sql = "SELECT * FROM db_name ORDER BY db_name ASC";
$statement = $dbAdapter->query($sql);
$result = $statement->execute();
$selectData = array();
foreach ($result as $res) {
$selectData[] = array(
'label' => $res['label_data'],
'attributes' => array(
'data-key' => $res['data_id']
),
'value' => $res['value_id']
);
// $selectData[$res['id']] = $res['name'];
}
return $selectData;
}

get configuration scope selector for custom module

I'm working on a module where I need to save the records based on the scope of website and store. For that I need to have the select box as its in the system->configuration.
How can I get that select box in my form and save the website/store value in database so that it can be displayed in the specific store/website? Any suggestions on it?
Now I'm trying it breaking into two fields -> website and store. Now, how can I change the options in store based on the website selected?
Finally, I'd written my own code for this.
$scope = array('default' => 'default');
foreach (Mage::app()->getWebsites() as $website) {
$scope['website_' . $website->getCode()] = $website->getName();
foreach ($website->getGroups() as $group) {
$stores = array();
foreach ($group->getStores() as $store) {
$stores[] = array(
'label' => $store->getName(),
'value' => 'store_' . $store->getCode()
);
}
$scope[] = array(
'label' => $website->getName(),
'value' => $stores
);
}
}
$fieldset->addField('website', 'select', array(
'label' => Mage::helper('designer')->__('Website'),
'name' => 'website',
'values' => $scope
));
Thanks to this post by Marius

Style text color inside a php function

I am trying to style the check symbol (&#10003) in my member profile tab on a Buddypress site. The tab is created in my functions.php file in my child theme shown in the code below. I want to make the check symbol green and bold. Because this is in PHP and part of a function I don't know how to accomplish this. Any ideas would be appreciated.
add_action('after_setup_theme','kleo_my_custom_tabs');
function kleo_my_custom_tabs()
{
global $bp_tabs;
$bp_tabs = array(); $bp_tabs['verify'] = array(
'type' => 'regular',
'name' => __('Verified &#10003', 'kleo_framework'),
'group' => 'Verify',
'class' => 'regulartab'
);
}
Try this:
'Verified <b style=\'color:#009900;\'>&#10003</b>'
add_action('after_setup_theme','kleo_my_custom_tabs');
function kleo_my_custom_tabs()
{
global $bp_tabs;
$bp_tabs = array(); $bp_tabs['verify'] = array(
'type' => 'regular',
'name' => __('Verified <b style="color:green;">&#10003</b>', 'kleo_framework'),
'group' => 'Verify',
'class' => 'regulartab'
);
}

setting Default Text inside Yii textarea

I'm new to Yii and i am facing issues with it. Hope some pros here can help me solve this. I bought a script online and i am editing it to my needs.
I want to have a text area with default texts. Example;
Name:
Age:
Sex:
what it is generating now:
<textarea class="span vertical medium" name="MAccount[accountInfo]" id="MAccount_accountInfo"></textarea>
what i want it to generate,or something like this :
<textarea class="span vertical medium" name="MAccount[accountInfo]" id="MAccount_accountInfo">Name: <br> Age: <br> Sex:</textarea>
something like above. But i only able to produce a textarea with blank/no content.below is my code,it is located inside a worklet.;
public function properties() {
$properties = array(
'elements' => array(
'accountInfo' => array(
'type' => 'textarea',
'class' => 'span vertical medium',
),
'email' => array(
'disabled' => true,
'append' => $this->model()->role == 'unverified' ? $this->t('unverified') : $this->t('verified'),
'hint' => $this->model()->role == 'unverified' ? $this->resendBtn() : '',
),
wm()->get('project.edit.buttons', array('step' => $this->step, 'projectId' => $this->project->id))->render('tools', array(), true),
),
'model' => $this->model(),
'class' => 'projectEditForm',
);
return $properties;
}
Default values are set in your model, not in your view. So you have to look in your model/ directory and locate the right model there. There you can add
public $accountInfo = "Name:\nAge:\nSex:";
<?php echo CHtml::activeTextArea($form,'abc',array('value'=>"12"));?>
$form->abc="Your text goes here"
it may help you

Categories