How to send url(id) through hiddenInput in ActiveForm (Yii2) - yii2

I am trying to send my URL ID value through ActivForm hidden input, but I didn't get the value.
<?= $form->field($modelsRoo, "[{$index}]booking_id")->hiddenInput(
['value'=> '$b_id'])->label(false); ?>
I am getting the value from Current Url like this.
and trying to pass it to Activeform HiddenField and on submitting this form I would like to save it in my Table.
One thing more I am using dynamicformwidget.
I am getting the value from Current Url like this:
<div class="col-sm-6">
<?=$form->field($modelsRoo, "[{$index}]unit")->textInput(['maxlength' =>true])?></div>
<div class="col-sm-6">
<?= $form->field($modelsRoo, "[{$index}]booking_id")->hiddenInput(
['value'=> '$b_id'])->label(false); ?>
</div>
When I submit the form I get booking_id value as Empty.
Any solution.

Related

How to change the field value in update form in Yii2

In my update form, I want to show the original value rather than it's id. Below is my _form.
<div class="mdc-meter-config-form">
<?php $form = ActiveForm::begin(['id'=>'con','options' => ['enctype' => 'multipart/form-data']]) ?>
<label class="control-label">Select Meters</label><br />
<input type="text" id="the-mter-id" class="form-control col-md-12" value="<?=$model->meter_id?>" />
<div style="clear: both;"></div>
<div id="selected_mters_container"></div>
<div style="clear: both;"></div>
<br/>
<?= $form->field($model, 'p_id')->dropDownList([''=>'Please Select']+\common\models\MdcProtocol::toArrayList()) ?>
<?= $form->field($model, 'time')
->dropDownList([''=>'Please Select','5' => '5', '10' => '10', '15' => '15','20'=>'20'])->label("Set Time (in seconds)") ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
In above view I want to change the 2 value to its actual one which is 4A60193390662
Dont know why you are not using the relation here for the meter to display the meter serial rather than the id.
Easiet way to avoid any further work as you want to just display it, 2 things you need to do
Assign the value to the input manually via relation.
Make the field disabled to exclude it out of the model collection array. (in case you use active form for the field).
I assume you have a relation to the meter in your current model with name getMeter() and the number you are trying to display 4A60193390662 is in field serial_number. You can change accordingly.
If you havent defined a relation than define one now
public function getMeter(){
return $this->hasOne(Meter::class,['id'=>'meter_id']);
}
Although you are using a custom html field you can still use the active form and mark the field disabled so that the activeform wont submit it with the model collection array and there wont be errors when saving the records like
meter_id should be an integer.
echo $form->field($model, 'meter_id')->textInput(['disabled' => 'disabled', 'value' => $model->meter->serial_number]);
try add an entry also for the field with value 4A60193390662 eg: $model->meter_name
<input type="text" id="the-mter-name" class="form-control col-md-12" value="<?=$model->meter_name?>" />
and if you don't want see the entry for meter_id .. you could use hidden input for this so mantain the related avlue for the model loading and popolation
And as suggested in comment by Michal Hyncica (sorry for improper charset ) you could wrap the input inside a check fo new record
<?php
if(!$model->isNewRecord) {
echo '<input type="text" id="the-mter-name" class="form-control col-md-12" value="' . $model->meter_name . '" />';
}

Update table cell value dynamically using angular6

I am working with an angular 6 application, in the HTML template I have some code as per below, just showing the table cell part of the array, also the table is built using divs.
<div class='table_small'>
<div class='table_cell'>Status</div>
<div class='table_cell'>
<p class="status" >{{incomingData.status}}</p>
</div>
</div>
Please note here that "data" is an array (*ngFor) and is being used in row data and there are multiple data in the table.
Now I have a situation wherein there is a button inside the table rows to cancel the particular order, when the user clicks in, a pop up/modal asks for user confirmation, if the user opts for 'Yes' it would change the status field value to "cancellation is in process" temporarily before it hits the service, once there is a successful response from the customer it would change the station to "cancelled".
I am really not sure how to do the cancellation within the table cell here, if anyone can give insight on this please do.
Thanks
You could pass the element to the function and edit its status:
<div class='table_small'>
<div class='table_cell'>Status</div>
<div class='table_cell'>
<p class="status" >{{incomingData.status}}</p>
</div>
<div class='table_cell'>
<button (click)="showCancelModal(incomingData)"> Cancel</p>
</div>
</div>
And then in the component something like this:
showCancelModal(incomingData) {
// logic for showing modal and retrieving user response
if( response === 'yes') {
incomingData.status = 'Cancel in progress';
yourService.cancel(incomingData)
.pipe( finally(() => incomingData.status = 'Cancelled') )
.subscribe();
}
}

How to customize Flash Message with inline css in cakephp3

In my Controller :
$this->Flash->success(__(' Your Data has been Saved Successfully. Sheets Name in this XLS file : <span style="color:#FF9900"> '.$SheetName.'</span>'));
In my success.ctp located in Element\Falsh :
<div class="alert alert-success fade in" onclick="this.classList.add('hidden')"> × <strong>Success!</strong> <?= h($message) ?> </div>
The Message is display like :
Now the question is how to use inline css in the flash message.
I think the soloution for your problem would be to use another layout for this type of message.
$this->Flash->set($message, $options[])
You can specify to use a specific element in the options. Something like this:
create a new confirmation.ctp inyour project:
<div class="[...]">
<?= h($message) ?>
<span style="color:#FF9900">
<?= h($params['sheetName']) ?>
</span>
</div>
now when you want to show the new confirmation use this code:
$this->Flash->set(__('The Message:'), [
'element' => 'confirmation,
'params' => [
'sheetName' => $SheetName
]
]);
This will display your custom flash element.

Yii2: how to stop inbuilt id generation by yii2 for each field in form

When i am adding form to view & specifying parameters as
<?= $form->field($model, 'form_name', ['options' => ['id' => 'formName', 'name' => 'formName']])->textInput(); ?>
But, when i run in the browser & check for view page source, there it shows me
<input type="text" id="submitform-form_name" class="form-control" name="SubmitForm[form_name]">
this disturbs my javascript calling for field input. How to stop yii2 from generating its own id???
You are passing options to ActiveField. If you want override id and name attributes, pass them in textInput() options like so:
<?= $form->field($model, 'form_name')->textInput(['id' => 'formName', 'name' => 'formName']) ?>
Generated html output will be:
<input type="text" name="formName" class="form-control" id="formName">
Note that after that client validation for this attribute will stop working and that attribute won't be massively assigned.

Call controller from submit button with CodeIgniter

I'm loading a view and I'm passing 2 arguments from a controller like this:
$this->load->view('confirm_data_v', $data);
In confirm_data_v view I'm receiving $data that is an array. In confirm_data_v I have a Submit button, but I want to call another controller when I click on it. The code of the button in confirm_data_v is:
<div class = "container">
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
confirm_data_v is a view to confirm to the user the information that he gave, so when he clicks "Save" button, it calls the controller to save it to the database.
You cant normally call a controller directly from a view - but you dont need to just make the button redirect to or ajax call any url you like (mysite.com/myurl in this example) on the button click and then route that to your controller:
$route['myurl'] = 'mycontroller';
Your main options for storing the data between the two pages are either storing in a session or a cookie or echoing all their data into hidden form fields and re-posting it (if it's sensative data - go with the session option):
http://ellislab.com/codeigniter/user-guide/libraries/sessions.html
If for whatever you really do want to call a controller from a view you ca do it using wiredesigns modular codeigniter : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
But generally speaking this flies in the face of the mvc architecture and there is no need to do it.
What i have get from your question that you want to submit data to controller n#1 from the view after loading it from a controller n#2
if this is the case you can do
Method # 1
<?php echo form_open('controller/function'); ?>
<div class = "container">
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
<?php echo form_close(); ?>
and you can access any other value with $this->post->input('input_name')
Method # 2
use Anchor instead of submit button
<div class = "container">
<div class="form-actions">
<?php echo anchor('controller/function/parm','Save',array('class'=>'btn btn-success')); ?>
</div>
</div>
and in your controller for example
function confirm_save($parm)
{
//save to database
//redirect back to the next controller you want with success message for example using session flash data
//or load another view but URL will be still the same whatever suits your case
}