0

I Created One Custom Module for Price Negotiate.And Put One Custom Button on "Product View Page" via "custom.phtml" file. If Button is Clicked than Popup will open and In Popup There is a Form Fields Like : Firstname , Lastname, etc. So how can I insert that Form Fields Data in to my custom table.

Any Kind of Help will appericiated.

Here Is My IndexController.php File.

<?php
class Sigmasolve_Pricenegotiate_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
            $this->loadLayout();
            $this->renderLayout();
    }

}

And Here Is My Template "pricenegotiate.phtml" file

<!--
<div class="add-to-cart-buttons">
<input type="Button" name="negotiate" value="Negotiate">
<button class="button btn-cart" type="button" title="Negotiate" data-target="#myModal" data-toggle="modal">Negotiate</button>
</div>
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">

    <button class="" style="font-size:20pt;color:black;background-color:sky-blue;border:2px solid #336600;padding:3px" type="button" title="Negotiate" data-target="#myModal" data-toggle="modal">Negotiate</button>
  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog" class="btn btn-info btn-lg">
    <div class="modal-dialog">

      <!-- Modal content-->
       <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Negotiate Price</h4>
        </div>
        <div class="modal-body">
            <form name="form" action="" method="post">
                <div class="form-group">
                  <label for="firstname">First Name :</label>
                  <input type="text" class="form-control" id="firstname" placeholder="Enter First Name" required>
                </div>

                <div class="form-group">
                  <label for="lastname">Last Name:</label>
                  <input type="text" class="form-control" id="lastname" placeholder="Enter Last Name">
                </div>

                <div class="form-group">
                  <label for="email">Email:</label>
                  <input type="email" class="form-control" id="email" placeholder="Enter email">
                </div>

                <div class="form-group">
                  <label for="telephone">Telephone:</label>
                  <input type="number" class="form-control" id="telephone" placeholder="Enter Number" maxlength="10" min="0" max="9">
                </div>

                <div class="form-group">
                  <label for="requestedprice">Requested Price:</label>
                  <input type="number" class="form-control" id="requestedprice" placeholder="Enter Your Price" min="0">
                </div>

                <div class="form-group">
                  <label for="qty">Quantity:</label>
                  <input type="number" class="form-control" id="qty" placeholder="Enter Quantity">
                </div>

                <div class="form-group">
                  <label for="note">Note:</label>
                  <input type="textarea" class="form-control" id="note" placeholder="Enter Note">
                </div>

                <button type="submit" class="btn btn-default">Place Request</button>
            </form>
         </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div> 

    </div>
  </div>

</div>

</body>
</html>

And Table Name Is pricenegotiate.

My config.xml File

<?xml version="1.0"?>
<config>
    <modules>
        <Sigmasolve_Pricenegotiate>
            <version>0.1.0</version>
        </Sigmasolve_Pricenegotiate>
    </modules>
    <frontend>
        <routers>
            <pricenegotiate>
                <use>standard</use>
                <args>
                    <module>Sigmasolve_Pricenegotiate</module>
                    <frontName>pricenegotiate</frontName>
                </args>
            </pricenegotiate>
        </routers>
        <layout>
            <updates>
                <pricenegotiate>
                    <file>pricenegotiate.xml</file>
                </pricenegotiate>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <pricenegotiate>
                <use>admin</use>
                <args>
                    <module>Sigmasolve_Pricenegotiate</module>
                    <frontName>pricenegotiate</frontName>
                </args>
            </pricenegotiate>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <pricenegotiate module="pricenegotiate">
                <title>Price Negotiate</title>
                <sort_order>72</sort_order>               
                <children>
                    <items module="pricenegotiate">
                        <title>Manage Price Negotiate</title>
                        <sort_order>0</sort_order>
                        <action>pricenegotiate/adminhtml_pricenegotiate</action>
                    </items>
                </children>
            </pricenegotiate>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <pricenegotiate>
                            <title>Price Negotiate Module</title>
                            <sort_order>200</sort_order>
                        </pricenegotiate>
                    </children>
                </admin>
            </resources>   
        </acl>
        <layout>
            <updates>
                <pricenegotiate>
                    <file>pricenegotiate.xml</file>
                </pricenegotiate>
            </updates>
        </layout>
    </adminhtml>   
    <global>
        <models>
            <pricenegotiate>
                <class>Sigmasolve_Pricenegotiate_Model</class>
                <resourceModel>pricenegotiate_mysql4</resourceModel>
            </pricenegotiate>
            <pricenegotiate_mysql4>
                <class>Sigmasolve_Pricenegotiate_Model_Mysql4</class>
                <entities>
                    <pricenegotiate>
                        <table>pricenegotiate</table>
                    </pricenegotiate>
                </entities>
            </pricenegotiate_mysql4>
        </models>
        <resources>
            <pricenegotiate_setup>
                <setup>
                    <module>Sigmasolve_Pricenegotiate</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </pricenegotiate_setup>
            <pricenegotiate_write>
                <connection>
                    <use>core_write</use>
                </connection>


            </pricenegotiate_write>
            <pricenegotiate_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </pricenegotiate_read>
        </resources>
        <blocks>
            <pricenegotiate>
                <class>Sigmasolve_Pricenegotiate_Block</class>
            </pricenegotiate>
        </blocks>
        <helpers>
            <pricenegotiate>
                <class>Sigmasolve_Pricenegotiate_Helper</class>
            </pricenegotiate>
        </helpers>
    </global>
</config>
  • please note your modifying code and table name you created – 3CE Mar 27 '17 at 18:54
  • @ 3CE : I am Edit the Question – H_Parekh Mar 28 '17 at 4:54
  • @H_Parekh provide your config.xml code – Murtuza Zabuawala Mar 28 '17 at 4:57
  • @ Murtuza Zabuawala : I Edit the question and append config.xml file – H_Parekh Mar 28 '17 at 6:19
3
    <?php
    class Sigmasolve_Pricenegotiate_IndexController extends Mage_Core_Controller_Front_Action
    {
        public function indexAction()
        {
                $this->loadLayout();
                $this->renderLayout();
        }
        public function saveAction(){
              $data = $this->getRequest()->getPost();
              $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
              $query = "INSERT INTO table_name (`first_name`, `last_name`, `email`, `telephone`,`request_price`,`quantity`,`note`)
VALUES ('".$data['first_name']."', '".$data['last_name']."', '".$data['email']."', '".$data['telephone']."', '".$data['request_price']."', '".$data['quantity']."', '".$data['note']."')";
$connection->query($query); 
        }

    }

this is simple insertion method us just create saveAction

in form just add action url of your controller. U can escape the query prevent sql injection

<!--
<div class="add-to-cart-buttons">
<input type="Button" name="negotiate" value="Negotiate">
<button class="button btn-cart" type="button" title="Negotiate" data-target="#myModal" data-toggle="modal">Negotiate</button>
</div>
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">

    <button class="" style="font-size:20pt;color:black;background-color:sky-blue;border:2px solid #336600;padding:3px" type="button" title="Negotiate" data-target="#myModal" data-toggle="modal">Negotiate</button>
  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog" class="btn btn-info btn-lg">
    <div class="modal-dialog">

      <!-- Modal content-->
       <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Negotiate Price</h4>
        </div>
        <div class="modal-body">
            <form name="form" action="<?php Mage::getBaseUrl('') ?>[controller_first_name]/save" method="post">
                <div class="form-group">
                  <label for="firstname">First Name :</label>
                  <input type="text" name='first_name' class="form-control" id="firstname" placeholder="Enter First Name" required>
                </div>

                <div class="form-group">
                  <label for="lastname">Last Name:</label>
                  <input type="text" name= "last_name" class="form-control" id="lastname" placeholder="Enter Last Name">
                </div>

                <div class="form-group">
                  <label for="email">Email:</label>
                  <input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
                </div>

                <div class="form-group">
                  <label for="telephone">Telephone:</label>
                  <input type="number" name="telephone" class="form-control" id="telephone" placeholder="Enter Number" maxlength="10" min="0" max="9">
                </div>

                <div class="form-group">
                  <label for="requestedprice">Requested Price:</label>
                  <input type="number" name="request_price" class="form-control" id="requestedprice" placeholder="Enter Your Price" min="0">
                </div>

                <div class="form-group">
                  <label for="qty">Quantity:</label>
                  <input type="number" name="quantity" class="form-control" id="qty" placeholder="Enter Quantity">
                </div>

                <div class="form-group">
                  <label for="note">Note:</label>
                  <input type="textarea" name="note" class="form-control" id="note" placeholder="Enter Note">
                </div>

                <button type="submit" class="btn btn-default">Place Request</button>
            </form>
         </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div> 

    </div>
  </div>

</div>
  • Hey Thanks for the answer . But I have Error Like "Invalid Url" – H_Parekh Mar 28 '17 at 6:59
  • in form action u put your {baseUrl}/controller_front_name/controllerName/method_saveAcion – Arshad Muhammad Mar 28 '17 at 7:03
  • any luck do u understand – Arshad Muhammad Mar 28 '17 at 7:14
  • in your config.xml fontName = pricenegotiate so url is {baseUrl}/pricenegotiate/index/save in form action – Arshad Muhammad Mar 28 '17 at 7:15
  • Yes I am Exactly wirte above action but i am getting 404 error – H_Parekh Mar 28 '17 at 7:25

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.