i have this code in codeigniter (section of form in codeigniter controller) :
$this->data['SalaryType'] = array(
'name' => 'SalaryType',
'id' => 'SalaryType',
'type' => 'text',
'value' => $this->form_validation->set_value('SalaryType'),
);
$this->data['DefaultSalary'] = array(
'name' => 'DefaultSalary',
'id' => 'DefaultSalary',
'type' => 'text',
'value' => $this->form_validation->set_value('DefaultSalary'),
);
$this->data['Salary_options'] = array(
'language' => 'monthly',
'world' => 'world'
);
(section of form in codeigniter view) :
<p>
Salary Type: <br />
<?php echo form_dropdown($SalaryType,$Salary_options,'monthly');?>
</p>
<p>
Default Salary: <br />
<?php echo form_input($DefaultSalary);?>
</p>
and i want use dropdown value but form send input value alone , and i can't access to dropdown value.
i check with print_r($_POST); but in post array observation 'DefaultSalary'.
You have initialized dropdown in wrong way
<?php echo form_dropdown($SalaryType,$Salary_options,'monthly');?>
use instead
<?php echo form_dropdown('DefaultSalary',$Salary_options,'language');?>
1st parameter is the name of the control
2nd parameter is the options array ->which is correct
3rd parameter is the selected index from the options array not value that can be in your case 'language' instead of 'monthly'
read form_helper
And you will be able to access it using $this->input->post('DefaultSalary'); and it will return the value of the option selected
May be your name attr of the drop down is not setting...
For adding id to form_drop down you can try this..
form_dropdown('country', $options_array, '1','id="select_id"')
Note : this is not tested.
Related
I am having issues rendering a modal when i click on add new button in yii with these error
CException
Property "BankMaster.swift_code" is not defined
This the view file (BankMaster/_form.php)
<?php echo $form->textFieldRow($model, 'swift_code', array('labelOptions' => array('class' => 'col-md-8 bank-master-settings-cls'), 'class' => 'col-xs-12 col-sm-12 col-md-12 col-lg-12', 'maxlength' => 100)); ?>
swift_code is the changes i made.
This the Model file (BankMaster.php)
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('full_name, short_name,iban_no,branch,payroll_status', 'required'),
array('full_name, address, email,swift_code', 'safe'),
array('opening_balance', 'numerical'),
array('ledger_code', 'uniqueCode'),
array('telephone,account_no, company_id', 'numerical', 'integerOnly' => true),
array('short_name,ledger_code', 'length', 'max' => 100),
array('full_name, email', 'length', 'max' => 100),
array('email', 'email'),
array('short_name', 'uniqueInLedger'),
// The following rule is used by search().
// #todo Please remove those attributes that should not be searched.
array('id, short_name,account_no,iban_no,opening_balance,op_balance_dc,branch_type,branch, full_name, address, telephone, email, payroll_status, is_default', 'safe', 'on' => 'search'),
);
}
swift_code is the changes i made too.
Then i added a column in erp_bank_master table
SOLUTION: "wp_105578" was the right database instead of "wpexp_dev"
I have Yii2 application which uses the Kartik plugin to initialize Select2 dropdowns in forms.
I have one particular Select2 which uses AJAX call to get the data for the drop down options.
<?=
$form->field($model, 'court_house_id', ['enableAjaxValidation' => true, 'selectors' => ['input' => '#' . $id . "-court-house"],'template' => FormHelper::GenerateFieldTemplate([6])])
->widget(Select2::classname(), [
'options' => ['id' => $id . "-court-house", 'placeholder' => Yii::t('app', 'Search court house...')],
'hashVarLoadPosition' => \yii\web\View::POS_READY,
'pluginOptions' => [
'dropdownParent' => new JsExpression("$('#$modalWindowId')"),
'allowClear' => true,
'minimumInputLength' => 2,
'language' => [
'errorLoading' => new JsExpression("function () { return '" . Yii::t('app', 'Search...') . "'; }"),
],
'ajax' => [
'url' => app\components\UrlMaker::link('data/court-house-list'),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(courthouse) { return courthouse.text; }'),
'templateSelection' => new JsExpression('function (courthouse) { return courthouse.text;}'),
]])
->label(Yii::t('app', 'Court House'), ['class' => FormHelper::GenerateLabelClassTemplate([3])]);
?>
Intentionally pasting all of the code, although most of it is irrelevant I would assume.
I have this loaded in multiple dynamically created forms thus all the strange ids and selectors. However, the form has different dropdown which controls whether some of the fields are shown (and required) or not. This particular field above is only shown in one of the scenarios which all the other variations of the form do not have it. So the model has the following validation:
[['court_house_id', 'staff'], 'required', 'on' => self::SCENARIO_ONE],
By the way staff is just a regular text field and everything works for it.
In order to change the scenario, I have the following line in the view with the form:
<?php $model->scenario = \app\models\MyModel::SCENARIO_ONE; ?>
The problem is that when I submit the form empty, the staff field gets marked in red as invalid but the court house is marked in green as valid although it is empty.
If I go into the model and remove the 'on' => self::SCENARIO_ONE part then everything works as expected - on empty submit the court house field also lights up in red but that would be a problem for the rest of my scenarios where this field is not needed.
Any ideas what might be causing the problem and how to resolve it?
Try to set the scenario in controller before calling save() method, for example
$model = new MyModel(['scenario' => MyModel::SCENARIO_ONE])
I have multiple forms in a tabbed layout and post to the same resource controller. These fields have the same field names with a few as arrays. Use case is password storage where depending on the type of password depends on the fields needed.
Input field
<?= Form::text('name', Input::old('name'), array('class' => ($errors->has('name')) ? 'invalid' : '', 'placeholder' => 'Application Name')) ?>
<?= Form::text("data['username']", Input::old('data["username"]'), array('class' => ($errors->has('data.username')) ? 'invalid' : '', 'placeholder' => 'Username')) ?>
<?= Form::text("data['password']", Input::old('data["password"]'), array('class' => ($errors->has('data.password')) ? 'invalid' : '', 'placeholder' => 'Password')) ?>
Validation rules
protected $rules = array(
'name' => 'required',
'data.username' => 'required',
'data.password' => 'required'
);
I have more data fields but this illustrates the use case.
I get errors properly with posting with empty fields and the old input is populated but I also get errors for filled fields. My post data shows populated fields.
Tested with just one form (could have done that the first time) and still had the error. My issue here was with the how the data['username'] was used.
Should be data[username] without the quotes. While post data and everything works with the quotes, the validator was not liking it.
I have this form:
$form = new Varien_Data_Form();
$costsForm = $form->addFieldset('costs', array(
'legend' => Mage::helper('starmall_config')->__('Shipping costs')
));
$data = array();
$costsArr = Mage::helper("starmall_config")->getShippingWeightRateList();
for ($i=0; $i < count($costsArr); $i++) {
$data["ship_cost_" . $i . "_from"] = $costsArr[$i]["from"];
$data["ship_cost_" . $i . "_to"] = $costsArr[$i]["to"];
// 1st column
$costsForm->addField("ship_cost_" . $i . "_from", 'text', array(
'name' => "ship_cost_" . $i . "_from",
'label' => $costsArr[$i]["label"],
'class' => 'required-entry',
'style' => 'width:50px',
'required' => true,
));
// 2nd column
// how to add a new field on the same row in another column
// 3rd column
// how to add a new field on the same row in another column
// 4th column
// how to add a new field on the same row in another column
}
It looks like this:
I want to add multiple input fields on the same row. Can this be done in Magento 1.7 ?
1) If you add fields directly to the form ( e.g. $form->addField(....) )
\app\design\adminhtml\default\default\template\widget\form\renderer\element.phtml
around line 29:
change:
<span class="field-row">
into:
<span class="field-row <?= $_element->getId();?>">
Now you have access to the form row with a class, and you can play with CSS to achieve what you need.
2) If you add fields to a form fieldset ( e.g. $fieldset->addField(....) )
provide parameter "container_id", for example:
$fieldset->addField('test_field', 'text', array(
'name' => 'test_field',
'label' => $this->__('Test field'),
'required' => false,
'disabled' => false,
'style' => 'width:50px;',
'container_id' => 'some-row-id'
));
After rendering you will see:
<tr id="some-row-id">
And now you can play easily with CSS to get what you need.
Kind Regards,
Janusz
Hello as Magento actually stores one value per path (see core_config_data table) the only way I can think of to achieve this would be to save your data in json or serialized format, then overwrite the renderer to split the information into separate input fields. even easyer would be to just add some javascript that automatically splits the json to separate inputs and then combines it back toghether on submit so you do not have to edit the models and renderers.
Try to use setNoSpan() method.
For example:
$checkbox = $this->addField('is_enabled', 'checkbox', array(
'onclick' => 'this.value = this.checked ? 1 : 0;',
'name' => 'is_enabled',
))->setNoSpan(true);
or
$checkbox = $this->addField('is_enabled', 'checkbox', array(
'onclick' => 'this.value = this.checked ? 1 : 0;',
'name' => 'is_enabled',
'no_span' => true
));
You can see usage of this element in follow file:
app/design/adminhtml/default/default/template/widget/form/renderer/element.phtml
<?php $_element = $this->getElement() ?>
<?php if($_element->getNoSpan() !== true): ?>
<span class="field-row">
<?php endif; ?>
<?php echo $_element->getLabelHtml() ?>
<?php echo $_element->getElementHtml() ?>
<?php if($_element->getNoSpan() !== true): ?>
</span>
<?php endif; ?>
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