Skip to main content

Add Dynamic data on magento admin form

<?php
class Ankur_Banners_Block_Adminhtml_Banners_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{

$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset("banners_form", array("legend"=>Mage::helper("banners")->__("Item information")));

$fieldset->addField('lable', 'hidden', array(
'label'     => Mage::helper('megamenu')->__('Add Images'),

'name' => 'label',
'after_element_html' => '<div id="add_more"></div><button id="add" class="add_field_button"  type="button" >Add Images</button>'
));



if (Mage::getSingleton("adminhtml/session")->getBannersData())
{
$form->setValues(Mage::getSingleton("adminhtml/session")->getBannersData());
Mage::getSingleton("adminhtml/session")->setBannersData(null);
}
elseif(Mage::registry("banners_data")) {
   $form->setValues(Mage::registry("banners_data")->getData());
}
return parent::_prepareForm();
}
}
 ?>
 <script type="text/javascript">

jQuery(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = jQuery("#add_more"); //Fields wrapper
    var add_button      = jQuery(".add_field_button"); //Add button ID
 
    var x = 1; //initlal text box count
    jQuery(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
             //text box increment
index=x;
            jQuery(wrapper).append('\
    <div id="banner' + index + '" >\
       <tr>\
  <a   class="remove_field">remove form</a></br\
        <td class="label"><label for="image">Image</label></td>\
<td class="value">\
         <input id="image' + index + '" name="image' + index + '" value="" type="file" class="input-file">\
<p class="note" id="note_image"><span>(*.jpg, *.png, *.gif)</span></p> </td>\
  </tr>\
     <tr>\
        <td class="label">\
<label for="image_path">Image Path</label></td>\
<td class="value">\
<input id="image_path' + index + '" name="image_path' + index + '" value="" type="text" class=" input-text">\
</td>\
    </tr></br>\
    <tr>\
        <td class="label"><label for="image_link">Image Link</label></td>\
<td class="value">\
       <input id="image_link' + index + '" name="image_link' + index + '" value="" type="text" class=" input-text"> </td>\
    </tr></br>\
    <tr>\
        <td class="label"><label for="short_order">Short Order</label></td>\
<td class="value">\
        <input id="short_order' + index + '" name="short_order' + index + '" value="" type="text" class=" input-text">            </td>\
    </tr></br>\
    </br>\
    </div>\
');

        x++;}
    });
 
    jQuery(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); jQuery(this).parent('div').remove(); x--;
    })

});

</script>

Comments

Popular posts from this blog

Magento Form Validators

Magento Javascript Validation Classes There are many more validation classes you can assign and I list them here as a reference. For more information on this please use Google, experiment with the code or contact me via my email or the contact form. validate-select Please select an option required-entry This is a required field validate-number Please enter a valid number in this field validate-digits Please use numbers only in this field. please avoid spaces or other characters such as dots or commas validate-alpha Please use letters only (a-z or A-Z) in this field. validate-code Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter. validate-alphanum Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed validate-street Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field validate-phoneStrict

How to create Guest Wishlist For Magento

Add to wishlist without customer login Add three tables CREATE TABLE `wishlist` ( `wishlist_id` INT(11) NOT NULL AUTO_INCREMENT, `customer_id` INT(11) NULL DEFAULT NULL, `shared` INT(11) NULL DEFAULT NULL, `sharing_code` VARCHAR(50) NULL DEFAULT NULL, `updated_at` TIMESTAMP NULL DEFAULT NULL, `cookie` VARCHAR(255) NULL DEFAULT NULL, PRIMARY KEY (`wishlist_id`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB AUTO_INCREMENT=0 ; CREATE TABLE `wishlist_item` ( `wishlist_item_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Wishlist item ID', `wishlist_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Wishlist ID', `product_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Product ID', `store_id` SMALLINT(5) UNSIGNED NULL DEFAULT NULL COMMENT 'Store ID', `added_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Add date and time', `description` TEXT NULL COMMENT '