$fieldset->addField('test_connection', 'submit', array(
'label' => Mage::helper('rpos_connect')->__('Test Connection'),
'required' => true,
'value' => 'Test',
'after_element_html' => '',
'tabindex' => 1
));
This is my PHP code to prepare a form with a button in my module block folder.Now I want this to call a function named testAction() in my Controller class.
You can use onclick as follows.
'onclick' => "setLocation('{$this->getUrl('*/controller/action')}')"
Related
I have below code of xeditable:
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
));
I would like to get the content of this field in my js.
I have tried to grab content of this in js using below code. But its not working
$(".editable editable-click").text;
You are missing a . before the class name editable-click.
You have an extra space after the class name .editable.
The method is text() in jquery not text property to get the text.
Change
$(".editable editable-click").text;
to
$(".editable.editable-click").text()
EDIT
You should call the script after the editable has loaded you can use the event onInit to trigger your javascript function from another file which is dependent on the editable input. For instance, if you have a function
function myFunction(){
//do something
$(".editable.editable-click").text()
//do something more
}
then you should try calling that function from the onInit event like below
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
'onInit' => 'js:function(){myFunction();}'
));
Try using onShown option of editable which will execute as soon as the editable form is shown. You can refer the code below.
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
'onShown' => 'js: function() {
var txtVal=$(this).data("editable").value; // This will hold your textbox value as soon as it opens.
someFunction(txtVal); //Call your JS function with textbox value as parameter.
}'
));
Then in your JS function, you can do so:
<script>
function someFunction(txtVal)
{
//Do anything with editable text box value
}
</script>
Hope this helps you.
I am creating a custom form for my extension. In the form I have few fields that I save in database. My problem is that once I save the fields they get saved in DB but after the page refresh the data in the fields gets empty.
I want these fields data to remain in the fields. How do I do that? Is there a way to do that.
Form code is in this file app\code\community\CompanyNmae\ModuleName\Block\Adminhtml\Suretaxconfig\Edit\Form.php
and save config method is in this file
app\code\community\CompanyNmae\ModuleName\controllers\Adminhtml\ModuleController.php
Code for Form.php is here. There no HTML or PHTML used in the project for my extension.
<?php
class CompanyName_Modulename_Block_Adminhtml_ModuleConfig_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
protected function _prepareForm() {
$form = new Varien_Data_Form (
array('id'=>'edit_form', 'action'=>$this->getData('action'), 'method'=>'post')
);
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('modulename')->__('ModuleName Settings'),
'class'=>'fieldset-wide'));
$fieldset->addField('companycode', 'text', array(
'name' => 'companycode',
'label' => Mage::helper('modulename')->__('Client Number'),
'title' => Mage::helper('modulename')->__('Client Number'),
'required' => true,
'after_element_html' => '<small>Enter Client Number</small>'
));
$fieldset->addField('validationkey', 'text', array(
'name' => 'validationkey',
'label' => Mage::helper('modulename')->__('Validation Key'),
'title' => Mage::helper('modulename')->__('Validation Key'),
'required' => true,
'after_element_html' => '<small>Enter Company Validation Key </small>'
));
$fieldset->addField('select_provider_type', 'select', array(
'label' => Mage::helper('modulename')->__('Default Provider Type'),
'class' => 'required-entry',
'required' => true,
'name' => 'providertype',
'onclick' => "",
'onchange' => "",
'value' => '1',
'values' => array('70' => '70', '99' => '99'),
'disabled' => false,
'readonly' => false,
'after_element_html' => '<small>Default Provider Type</small>',
'tabindex' => 1
));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
you can fetch data from database and fill that data into fields or you can use session and store form post values into it before saving the data into database and when it redirects on your form page you can check if values are exists then you fill them in form
Your question is little confusable, I'm assuming that you want to keep fields data field after the form submit....
Is this is the scenario then you can use PHP Sessions to store data in sessions and check on page load if session is set then display it.
Like:
PHP
session_start();
// you can set session on form submit using if(isset($_POST)){//set session here}
$_SESSION['example'] = "Example Value";
HTML
<input type="text" name="example" value="<?=(isset($_SESSION['example']) ? $_SESSION['example'] : ''); ?>"/>
I have a controller with a add() function and create() function. The add function posts to create.
The form is displayed using the form helper. In the add() function, I have an array to set the form input attributes that looks like the following:
$this->data['form'] = array(
'label_attributes' => array(
'class' => 'col-lg-2 control-label'
),
'media_name' => array(
'class' => 'form-control',
'id' => 'media_name',
'name' => 'media_name',
'value' => set_value('media_name')
),
'media_link' => array(
'class' => 'form-control',
'id' => 'media_link',
'name' => 'media_link',
'value' => set_value('media_link')
),
'media_width' => array(
'class' => 'form-control',
'id' => 'media_width',
'name' => 'media_width',
'size' => '4',
'maxlength' => '4',
'value' => ($this->form_validation->set_value('media_width')) ? $this->form_validation->set_value('media_width') : '640'
),
'media_height' => array(
'class' => 'form-control',
'id' => 'media_height',
'name' => 'media_height',
'value' => ($this->form_validation->set_value('media_height')) ? $this->form_validation->set_value('media_height') : '360'
),
'media_description' => array(
'class' => 'form-control',
'id' => 'media_desription',
'name' => 'media_desription',
'value' => $this->form_validation->set_value('media_desription')
)
);
When I post to the create() function, I lose access to the data['form'] values. Should all this information just be in the view or is it possible to put it in the model so I can load it whenever needed? When I tried to put it in the model, I had issues with the 'value' attributes even if I loaded the form_validation library in the model.
Because the controller class is renewed when a new request comes, so the problem with your code is that, $this->data is created when you visit the add function, while when you post to create function, the controller class is renewed again, there is no $this->data at all at this time.
If you want to pass data from one request to another request, you can pass the data via view or model.
Hope helps!
I have an admin form field(textbox),
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
));
I need to set a default value for this text field. I tried, setting 'value' => '120', in it. But its not working.
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'value' => '120',
));
How to set a defalt value in that field?
In my case, setValues() function was overriding the 'value' that I had set for the field.
Cause:
In my _prepareForm() function, I set the value as below:
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'value' => '120',
));
At the end of _prepareForm() function, there was the following line of code which would reset the form values:
$form->setValues($model->getData());
Solution:
Set model data before setValues() function as below:
if (!$model->getId()) {
$model->setData('ajax_time_interval', '120');
}
$form->setValues($model->getData());
you can do that by adding "default" attribute in field configurations.
$fieldset->addField('ajax_time_interval', 'text', array(
'label' => Mage::helper('dealroom')->__('Page Refresh Time Interval'),
'class' => 'required-entry',
'required' => true,
'name' => 'ajax_time_interval',
'default' => '120',
));
Remove the last semicolon....
Check this site help-me a lot:
http://www.excellencemagentoblog.com/magento-admin-form-field
Gl mf
I would like to reload the form, or preferably just the values, by using 'onChange'. There are several elements in the form that needs to be updated when changing the project id.
$this->addElement('select', 'project_id', array(
'label' => t('Project'),
'multiOptions' => $data,
'filters' => array('Int'),
'value' => 0,
'required' => true,
'disableTranslator' => true,
'validators' => array(),
'onChange' => 'Javascript:window.location.reload(false)'
));
You can change your onChange to call a custom javascript function instead - which will change any fields you need to change, and then submmit the form.