0

I have a block of code that I call for a dropdown in the form. The issue is when the product data is 'submitted' from the save button the form the old data stay there, but only in dropdowns . The 'Text' fields remove their data, but all the dropdown like the one below show the 'default' as the last chosen option.

For example if 'manufacturer' equals 'Nike' and 'name' equals 'Nike Shoes'...

The 'Nike Shoes' will be removed, but the 'Nike' in the dropdown manufacturer will remain. in this instance, it's causing accidental errors on choosing a field that is 'required', but since it keeps the old data, it's easy to bypass the the required validation.

<div>
                <label for="product[manufacturer]"><em>*</em><?php echo $this->__('Brands') ?></label>
                <?php if(!empty($manufacturer_values)):?>
                <select name="product[manufacturer]" id="product[manufacturer]" required="required">
                    <?php echo "<option value=\"$value\"></option>";?>
                    <?php foreach($manufacturer_values as $value): ?>
                        <option value="<?php echo $value['value']?>" <?php if($product->getData('manufacturer') == $value['value']) echo "selected='selected'"?>><?php echo $value['label']?></option>
                    <?php endforeach; ?>
                </select>
                <?php else: ?>
                <?php endif; ?>
    </div>

This form is built of a mobile theme, but show what happens.

enter image description here

Here is the Block

<?php

class AuIt_MAdmin_Block_Parentbin_Form extends Mage_Adminhtml_Block_Template{
    public function getProduct()
    {
        return Mage::registry('search_product');
    }
}

Here is the phtml

<?php ?> <a href="<?php echo $this->getUrl('depot/dashboard/index');?>" data-mini="true" data-role="button" data-icon="arrow-l" data-inline="true"><?php echo $this->__("BACK")?></a>

<div data-role="content"  data-iscroll  >   <p><?php echo $this->__("Parent BIN")?></p>     <?php if ( $product  = $this->getProduct() ) :?>        <?php       /* @var $product Mage_Catalog_Model_Product */
                ?>

        <form enctype="multipart/form-data" action="<?php echo $this->getUrl('*/*/save');?>" method="post" class="ui-body ui-body-a ui-corner-all" data-ajax="false" data-cache="false">            <div>
                <label for="product[sku]"><?php echo $this->__('SKU') ?></label>
                <input type="text" name="product[sku]" id="product[sku]" value="<?php echo $product->getSku();?>" disabled/>            </div>          <div>
                <label for="product[erp_bin_location]"><em>*</em><?php echo $this->__('BIN') ?></label>
                <input type="text" name="product[erp_bin_location]" id="product[erp_bin_location]" value="<?php echo $product->getData('erp_bin_location');?>"required="required"/>             </div>

                        <div>
                <label for="product[erp_line_items]"><em>*</em><?php echo $this->__('Number of Items') ?></label>
                <input type="text" name="product[erp_line_items]" id="product[erp_line_items]" value="<?php echo $product->getData('erp_line_items');?>" required="required"/>          </div>          <div>
                <label for="product[msrp]"><?php echo $this->__('MSRP') ?></label>
                <input type="text" name="product[msrp]" id="product[msrp]" value="<?php echo $product->getMsrp();?>" disabled/>             </div>          <div>
                <label for="product[erp"_stock]"><?php echo $this->__('Stock') ?></label>
                <input type="text" name="product[erp_stock]" id="product[erp_stock]" value="<?php echo $product->getErpStock();?>" disabled/>           </div>          <div class="ui-block-b"><button type="submit" data-theme="a"><?php echo $this->__('Save') ?></button></div>             <input type="hidden" name="mode" value="update"/>           <input type="hidden" name="id" value="<?php echo $product->getId()?>"/>             <input type="hidden" name="product[erp_sku]" value="<?php echo trim($product->getAttributeText('erp_sku'));?>"/>            <input type="hidden" name="product[erp_bin_location_hidden]" id="product[erp_bin_location_hidden]" value="<?php echo $product->getData('erp_bin_location');?>" readonly="readonly"/>

                        <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey()?>"/>        </form>         <br/><br/>  <?php endif;?>

    <form action="<?php echo $this->getUrl('mobile_admin/parentbin/search');?>" method="POST" class="ui-body ui-body-b ui-corner-all">      <h2><?php echo Mage::helper('catalog')->__('Search') ?></h2>        <div data-role="fieldcontain">          <label for="searchvalue"><?php echo Mage::helper('adminhtml')->__('Filter Attribute: %s (see config)',Mage::getStoreConfig('auit_madmin/stock/attribute')) ?></label>           <input type="text" id="searchvalue" name="searchvalue"  />

        </div>

        <input type="submit" data-role="button" data-inline="true" data-theme="b"  value="<?php echo Mage::helper('adminhtml')->__('Search') ?>"/>      <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey()?>"/>    </form> </div>
  • Please post the code from your block's class file – Shawn Abramson Oct 5 '16 at 5:30
  • Sure, but I'll add the block as it is only loading the search before the load, and the phtml from the design. See edited – Anthony Cicchelli Oct 6 '16 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.