1

I have create a field English video and save to data in database but I can't set value in edit time

I have used this code for set value.

$fieldset->addField('title', 'text', array(
            'label'     => Mage::helper('ultimate_option')->__('English Video'),
            'id'  => 'option_english',
            'name'      => 'option_english',
            'after_element_html' => '<table id="modulename_tbl_data_English" cellspacing="0">
                                <button id="English" class="add" type="button" title="Add"><span><span><span>Add</span></span></span></button>
                                </table>',
            'value'  => 'hello !!'         
        ));     

but getting this blank result

enter image description here

How can I set value for English text box at edit time.

2
  • can you show your full Form.php file? Commented Jun 25, 2015 at 13:14
  • @meenakshi I am using umc extension for create module I need multiple field for add video so I add this field extra by hardcode and save to db by insert query but in edit time i want to set value but I am unable to set normal value to this field Commented Jun 25, 2015 at 13:17

3 Answers 3

5

I assume you have after the form definitions something like this:

$form->setData($data);

or

$form->addData($data);

If you do, add this line above it:

if (!isset($data['option_english'])) {
    $data['option_english'] = 'Your default value here';
}
2
  • Where I use this code ? Commented Jun 25, 2015 at 13:23
  • In the same class, same method. After defining the form. If you don't have the line $form->setData($data); or $form->addData($data); add it and before it add the rest of the code I suggested.
    – Marius
    Commented Jun 25, 2015 at 13:40
0

somewhere in the code you might have called

$form->setValues($somethingHere);

Replace that line with:

$form->addValues(array('option_english'=> 'default_Value'));
0
0

For anyone looking and are working on 1.9 and have the below

if($model){
    $form->setValues($model->getData());
}

You can do the following without having to edit your existing data, just above that code place:

if($model->getData('fieldName') == ""){
    $model->setData('fieldName', "yourValue");
}

Of course you can check isset and such but here is the basic version of setting defaults.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.