Showing posts with label Custom Fields. Show all posts
Showing posts with label Custom Fields. Show all posts

Monday, September 9, 2013

Magento: Newsletter Custom fields Title, Firstname, lastname, email | How to add Title, Firstname, lastname, email in newsletter module.

Magento: Newsletter Custom fields Title, Firstname, lastname, email | How to add Title, Firstname, lastname, email in newsletter module.


We have provided solution to add custom input fields in magento newsletter module. How to add the custom input fields on newsletter section Title, Firstname, lastname, email. Also we implemented newsletter in magento page.

We need to follow the below steps,

Create newsletter form in html format

 
<form action="http://websitename,com/newsletter/subscriber/new/" method="post" id="newsletter-validate-detail">
<div class="form-subscribe"> <div class="input-box">
<table class="colors_lines_light"  border="0" cellspacing="1" cellpadding="5" align="center">
<tbody>
<tr >
<td width="95">Title:</td>
<td width="282"><select id="subtitle" name="subtitle" title="subtitle" class="required-entry">
                                    <option value="" selected="selected"></option>
                                    <option value="Mr">Mr</option>
                                    <option value="Ms">Ms</option>
                                    <option value="Mrs">Mrs</option>
                                    <option value="Sir">Sir</option>
                                    <option value="Lord">Lord</option>
                                    <option value="Dr">Dr</option>
                                    <option value="Prof">Prof</option>
                                    <option value="Rev">Rev</option>
                                </select>
</td>
</tr>
<tr >
<td width="95">First Name:</td>
<td width="282"><input type="text" name="subfirstname" id="subfirstname"  size="30" maxlength="50"  class="input-text required-entry" /></td>
</tr>
<tr >
<td width="95">Last Name:</td>
<td width="282"><input type="text" name="sublastname" id="sublastname"  size="30" maxlength="50" class="input-text required-entry" /></td>
</tr>
<tr >
<td width="95">Email Address</td>
<td width="282"> <input type="text" name="email" id="newsletter" title="Sign up for our newsletter" class="input-text required-entry validate-email" size="30" maxlength="100" ></td>
</tr>
<tr >
<td width="95">&nbsp;</td>
<td width="282"><button type="submit" title="Submit" class="button" ><span><span>Sign Up</span></span></button>
</td>
</tr>
</tbody>
</table>
  </div>  </div></form>

<script type="text/javascript">
//<![CDATA[
    var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
    new Varien.searchForm('newsletter-validate-detail', 'newsletter', '');
//]]>
</script>


 

Update grid.php in the following location

 
Location: app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/


find the function  protected function _prepareColumns()    {    and add the below


 $this->addColumn('subtitle', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber Title'),
            'index'     => 'subscriber_title',
            'default'   =>    '----'
        ));
       
        $this->addColumn('subfirstname', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber First Name'),
            'index'     => 'subscriber_firstname',
            'default'   =>    '----'
        ));
        $this->addColumn('sublastname', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber Last Name'),
            'index'     => 'subscriber_lastname',
            'default'   =>    '----'
        ));









 



update the SubscriberController.php in the below location

Location for update: app/code/core/Mage/Newsletter/controllers/


 find the function    public function newAction()    { 

 and  replace

  $status = Mage::getModel('newsletter/subscriber')->subscribe($email);  

add the below

 if ($this->getRequest()->getPost('subtitle'))
                {
                     $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                     $subtitle     = (string) $this->getRequest()->getPost('subtitle');
                     $subscriber->setSubscriberTitle($subtitle);
                   
                }
               

                 if ($this->getRequest()->getPost('subfirstname'))
                {
              
                     $subfirstname     = (string) $this->getRequest()->getPost('subfirstname');
                     $subscriber->setSubscriberFirstname($subfirstname);
                   
                }
                if ($this->getRequest()->getPost('sublastname'))
                {
                   
                     $sublastname     = (string) $this->getRequest()->getPost('sublastname');
                     $subscriber->setSubscriberLastname($sublastname);
                   
                }
           
                    $status = Mage::getModel('newsletter/subscriber')->subscribe($email,$subtitle, $subfirstname, $sublastname);
           




 

update the Subscriber.php in the below locations

 
Location : app/code/core/Mage/Newsletter/Model/


 find function  

public function subscribe($email) 

and replace 

public function subscribe($email,$subtitle=null, $subfirstname=null, $sublastname=null)

in this function find 

$this->setSubscriberEmail($email);


add below following

            $this->setSubscriberTitle($subtitle);
            $this->setSubscriberFirstname($subfirstname);
            $this->setSubscriberLastname($sublastname);


 

Finally update the magento database,

  Now open the magento database and open the "newsletter_subscribers".
 Add the extra column what you want fields in the newsletter. Here we added three fields like subscriber_title, subscriber_firstname, subscriber_lastname











Hope this may be helpful. please share and provide suggestion to improve. thanks

By PHP with 5 comments

    • Popular
    • Categories
    • Archives