2

Below is my Contact Form Email id Box :

<div class="field">
                    <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
                    <div class="input-box">
                        <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
                    </div>
                </div>

How can i give condition here like registered customer only submit enquiry form. this condition should check from my customer Database, if email id is not registered enforced to signup.

I am getting so many spam emails every day.

1

You can put log in condition like below code. i was use this condition if user is logged in then show this field else another

<?php                           
                            //Get the customer session and check if the customer is logged in
                            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                            // Get the customer object from customer session
                            $customer = Mage::getSingleton('customer/session')->getCustomer();

                        ?>
                        <div class="col-xs-12">

                            <div class="field col-xs-6">
                                <label for="name" class="formlabel"> Full Name <span class="required">*</span> </label> 
                                <input class="textfield" type="text" value="<?php echo $customer->getName(); ?>"  name="fname" id="fname" />
                            </div>

                            <div class="field col-xs-6">
                                <label class="formlabel"> Email <span class="required">*</span> </label> 
                                <input class="textfield" type="email" value="<?php echo $customer->getEmail(); ?>" name="email" id="email" />
                            </div>

                        </div>
                        <div class="clear"></div>

                        <?php } 
                        else {
                        ?>

                        <div class="col-xs-12">

                            <div class="field col-xs-6">
                                <label for="name" class="formlabel"> Full Name <span class="required">*</span> </label> 
                                <input class="textfield" type="text"  data-required="true" name="fname" id="fname" placeholder="Please Enter Your Name" />
                            </div>

                            <div class="field col-xs-6">
                                <label class="formlabel"> Email <span class="required">*</span> </label> 
                                <input class="textfield"  data-required="true" type="email" name="email" id="email" placeholder="Please Enter Email Address" />
                            </div>

                        </div>
                        <div class="clear"></div>

                        <?php } ?>
|improve this answer|||||
  • hi Wajahat, this is my condition for my FORM -> justpaste.it/1jo3v Its not working... could you kindly help me. – zus Apr 16 '18 at 6:20
  • send me your email – Wajahat Bashir Apr 16 '18 at 12:12
  • zus710@gmail.com – zus Apr 16 '18 at 12:28
  • Let me know when you send the code... – zus Apr 16 '18 at 12:29
  • i sent you code file open and search (Product Enquiry) in that form i'm using these condition you can understand easily.. and this code is working fine. – Wajahat Bashir Apr 16 '18 at 13:37
1

You can use an observer to check if you customer is logged in to display contact us form

Create a module and in config.xml file define your observer

config.xml

    <events>
        <controller_action_predispatch_contacts_index_index>
            <observers>
                <contact_check_customer>
                    <type>singleton</type>
                    <class>Namespace_Modulename_Observer</class>
                    <method>checkCustomer</method>
                </contact_check_customer>
            </observers>
        </controller_action_predispatch_contacts_index_index>                                    
  </events>

In your Observer File

Observer.php

<?php
class Namespace_Modulename_Model_Observer
{

    public function checkCustomer(Varien_Event_Observer $observer)
    {
        if(!Mage::getSingleton('customer/session')->isLoggedIn()){
            $controllerAction = $observer->getEvent()->getControllerAction();
            $controllerAction->getResponse()
                    ->setRedirect(Mage::getUrl('customer/account/login'));
        }
    }
}
|improve this answer|||||

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.