1

I have created a custom form page where customers can submit details like name, email, etc and all the details are stored in a custom database table. The form includes following input fields.

Name Field:

<input id="name" name="name" value="<?php echo $_SESSION['name']; ?>" type="text" /> 

Email Field:

<input type="text" id="email" value="<?php echo $_SESSION['email']; ?>" name="email" />

In in the same form I have created another checkbox with subscription to newsletter option with the following code:

<?php
                        $email = $_POST['email'];
                        $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
                        if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
                            Mage::getSingleton('core/session')
                               ->addSuccess($this->__('Confirmation request has been sent.'));
                        }
                        else {
                            Mage::getSingleton('core/session')
                                ->addSuccess($this->__('Thank you for your subscription.'));
                        }
                    ?>

In the Thank You page I do see the Thank you for your subscription. message and the subscription does happens in Magento but for some reason the email that the customers entered in the email field is not being posted to the newsletter so how do I fix it.

Update:

I was able to post the email to Magento Newsletter email field by moving the

    if (isset($_POST['is_subscribed'])) {
        $subscribeemail = $_POST['email'];
        $status = Mage::getModel('newsletter/subscriber')->subscribe($subscribeemail);
            if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
                Mage::getSingleton('core/session')
                 ->addSuccess($this->__('Confirmation request has been sent.'));
            }
            else {
                Mage::getSingleton('core/session')
                ->addSuccess($this->__('Thank you for your subscription.'));
            }
    }

inside QuoteController.php file of the module. Customer First Name is still empty so how do I post Name field as Customer First Name?

2

Get customer first name from customer/session and place it in the hidden field.

if (Mage::getSingleton('customer/session')->isLoggedIn()) {

    // Load the customer's data
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $customer->getName(); // Full Name
    $customer->getFirstname();
}

or you can directly get First name in controller also.

  • As of now we have disabled customer registration and login function. I would like to get the name from Name input field that is filled in the form and post it as subscribers first name. – Kevin S Dec 11 '14 at 8:38
  • then you can get first name just as you got email – HungryDB Dec 11 '14 at 8:45

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.