19

I am trying to edit the product edit page (first tab) in Magento and would like to move the quantity (as well as a few other things) from their respective tabs up to the first page. I see

<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="product_edit_form" enctype="multipart/form-data">
<?php echo $this->getBlockHtml('formkey')?>
<div style="display:none"></div>
</form>

and know that the code for the quantity textbox is

    <tr>
        <td class="label"><label for="inventory_qty"><?php echo Mage::helper('catalog')->__('Qty') ?><span class="required">*</span></label></td>
        <td class="value">
            <?php if (!$_readonly):?>
            <input type="hidden" id="original_inventory_qty" name="<?php echo $this->getFieldSuffix() ?>[stock_data][original_inventory_qty]" value="<?php echo $this->getFieldValue('qty')*1 ?>"/>
            <?php endif;?>
            <input type="text" class="input-text required-entry validate-number" id="inventory_qty" name="<?php echo $this->getFieldSuffix() ?>[stock_data][qty]" value="<?php echo $this->getFieldValue('qty')*1 ?>" <?php echo $_readonly;?>/>
        </td>
        <td class="value scope-label"><?php echo Mage::helper('adminhtml')->__('[GLOBAL]') ?></td>
    </tr>

Does anyone know where the code for the first tab is? Does it have something to do with formkey?

Thanks!

43

Form keys in Magento are a means of preventing against Cross Site Request Forgery - explained brilliantly by Ashley Schroder here but, in short, it's to keep you safe from people trying to post to your forms (like add to cart) from other sites posing as you.

This can be dangerous because someone could theoretically create their own form and post to any form handler controller action in your store without you even being aware. CSRF protection essentially ignores any post which fail a check on the included form_key parameter with the form post.

So, what does <?php echo $this->getBlockHtml('formkey')?> do? It tells Magento to look for a layout block with the name "formkey" and output it. In Magento this is usually some file which has this in it:

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

This instructs Magento to output and store a unique form key for a user session. All CSRF-protected Magento controller actions will verify against this before doing anything of value.

HTH!

  • Well that certainly explains what they do and I thank you very much. Now I'm still left trying to figure out how to get that quantity <tr> into my product edit first tab. Thoughts? I can do it just at the top but I want it to be one of the included fields so it looks like it was supposed to be there. – new2programming Nov 13 '14 at 21:06
  • The last sentence leaves me to wonder if there are some Magento controllers that aren't CSRF protected o_O – Nick Rolando Aug 3 at 3:13

Your Answer

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

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