1

HI all i am a noob at magento. can someone please help me please I have two database which are . http://s30.postimg.org/ujldkz381/Screenshot_2015_01_21_13_11_48.png)

http://s28.postimg.org/fsfzlx0r1/Screenshot_2015_01_21_13_13_27.png)

I have option to save to the database which has the following code in the template.

  </script>
    <div class="page-title">
            <h1><?php echo $helper->__('Promotion Settings') ?></h1>
    </div>
    <form action="<?php echo $this->getUrl('socialcoupon/index/savecoupon') ?>" enctype="multipart/form-data" method="post" id="form-coupon-save">
    <div class="fieldset">
                <h4 class="legend"><?php echo $helper->__('Create Promotion') ?></h4>
                    <ul class="form-list" id="wk_bodymain">
                        <input type="hidden"  name="customerid" value="<?php echo $customerid?>"/>
            <li>
                                <label class="required"><em>*</em><?php echo $helper->__('Discount Amount') ?>:</label>
                                <div class="input-box">
                                    <input type="text" class="required-entry input-text" name="discountamt" id="discountamt" value="0"/>
                                </div>
            </li>
            <li>
                                <label class="required"><em>*</em><?php echo $helper->__('Number of coupons') ?>:</label>
                                <div class="input-box">
                                    <input type="text" class="required-entry input-text" name="numcoupons" id="numcoupons" value="0"/>
                                </div>
            </li>
            <li>
                                <label class="required"><em>*</em><?php echo $helper->__('Start Date (MM/DD/YYYY)') ?>:</label>
                                <div class="input-box">
                                    <input type="text" id="datepicker" class="required-entry input-text" name="fromdate" id="fromdate" value="0"/>
                                </div>
            </li>
            <li>
                                <label class="required"><em>*</em><?php echo $helper->__('End Date (MM/DD/YYYY)') ?>:</label>
                                <div class="input-box">
                                    <input type="text" id="datepicker2" class="required-entry input-text" name="todate" id="todate" value="0"/>
                                </div>
            </li>
            <li>
                                <label class="required"><em>*</em><?php echo $helper->__('Product SKU)') ?>:</label>

                                <div class="input-box">
                                    <select name="sku_in" id="sku_in" onChange="OnDropDownChange(this);">



            </span>

I have done the delete code and it works. This is my delete code

  Public function deletecouponAction ()  {

    // get id
    //$id = getParam(couponid);
   $id = $this->getRequest()->getParam(id);


$model = Mage::getModel('salesrule/coupon');
try {
    $model->setId($id)->delete();
    echo "Data deleted successfully.";

} catch (Exception $e){
    echo $e->getMessage(); 
}
  $this->_redirect('socialcoupon/index/');    

    // select required table
   // $table = Mage::getSingleton("core/resource")->getTableName('salesrule/coupon');


    //$db = Mage::getSingleton('core/resource')->getConnection('core_write');


    //delete data and edit parameter accordingly
    //$db->delete($table, array('coupon_id=?'=> $id));

    //$data= $this->getRequest()->getParams();
    //$_product = Mage::getModel('salesrule/coupon')->load($data[26])->delete();


    // ob_flush();
       // flush();

}

I want a way to edit those database with a popup. The code goes in indexcontroller. Thank you. The save works too. the form have 4 stuffs inside.

0

I think you are lagging with an idea for how to implement this. For this part I can help you here. But I cant here provide a full-packed answer here since it is too time consuming and lengthy job.

Desclaimer : Here I am assuming you have a working module with name Namespace_Modulename

  1. Basically you need to have a popup section which consists of an edit form. So definitely you need to use prototype.js, javascript or jquery in this case. That is up to you. But what i am suggesting you is, you should create a block for this form. You need to include this block in your layout and by default this block should be hided. When user click on edit link, this block should be poped-up to the user. Below I will show you how can you add a new block in your layout.

File: app\design\frontend\<package>\<theme>\layout\local.xml

<layout>
    <namespace_modulename_index_index> <!-- layout handle for the loaded page here -->
        <reference name="content">
           <block type="core/template" name="popup.edit.form" template="namespace_modulnename/popup/editform.phtml" />
        </reference>
    </namespace_modulename_index_index>
</layout>

Here namespace_modulename_index_index layout handle reference for the page which need to hold the edit block. Here the important part is the inclusion of popup.edit.form block.

  1. Next step is to define your editform.phtml file. This file is going to hold the edit form and associated script. This is how it is going to looks like.

File : app\design\frontend\<package>\<theme>\template\namespace_modulename/popup/editform.phtml

<div id="popup-edit-form-container" style="display:hidden">
    <form id="popup-edit-form" action="<?php echo Mage::getUrl('namespace_modulename/index/edit') ?>">
         <!-- put your form fields here -->
    </form>
</div>
<script type="text/javascript">

    //script to show popup box when click on edit link here

    //you can have an ajax request here when button is pressed.

</script>

As you can see we have an edit form which is intended to do post to the url www.domain.com/yourModulePath/index/edit. This means you need to define an editAction() inside your IndexController.php.

Next you have two option to submit your form at least. You can submit your form via ajax request or by normal form submission way. Either way, you need to direct the action to the above specified url.

  1. Now your controller method should look like this.

    <?php
    class Namespace_Modulename_IndexController extends Mage_Core_Controller_Front_Action
    {
        public function editAction()
        {
             //get posted data
             $data = $this->getRequest()->getPost();
    
             //perform something with this data
        }
    }
    

Now in editAction, we will first get all posted data and then do a update or save action there. That's it.

I hope it will give you some idea.

| improve this answer | |
  • if the answer helped you, then please accept this answer and thus congratulate me... let us together be a part of our community. :-) – Rajeev K Tomy Jan 23 '15 at 2:07
  • I cant vote cuz i am new. it says my reputation should reach 15 to accept your answer. – noob Jan 23 '15 at 3:20
  • this is your question and you can definitely accept it. It is done by mark the tick sign that you can see in the left side of my anwer. :) – Rajeev K Tomy Jan 23 '15 at 4:11
  • done. do you have skype id? – noob Jan 23 '15 at 10:13
  • yes. What is your intention ? – Rajeev K Tomy Jan 23 '15 at 10: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.