0

I want to get the first and last name in a custom contact form in Magento 1.9.x

in my custom_contact.phtml file I have this:

<?php


if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    // Get the customer object from customer session
    $customer = Mage::getSingleton('customer/session')->getCustomer();

    $custID = $customer->getID();//get customer id
    $custFirstName = $customer->getFirstname();
    $custLastName = $customer->getLastname();
    $custEmail = $customer->getEmail();//get customer email
}

?>

   <div class="field">
                    <label for="xfirstname" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('First Name') ?></label>
                    <div class="input-box">
                        <input type="text" name="xcustom" id="xcustom" value="" style="display:none !important;" />
                        <input name="xfirstname" id="xfirstname" title="<?php echo Mage::helper('contacts')->__('First Name') ?>" value="<?php echo $custFirstName ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field">
                    <label for="xlastname" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Last Name') ?></label>
                    <div class="input-box">
                        <input name="xlastname" id="xlastname" title="<?php echo Mage::helper('contacts')->__('Last Name') ?>" value="<?php echo $custLastName ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>

and I add this conditions in the transactional email:

{{if xcustom}}First Name: {{var customer.xfirstname}}{{else}}{{/if}}
{{if xcustom}}First Name: {{var customer.xlastname}}{{else}}{{/if}}

Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}



Comment: {{var data.comment}}

but Firsname and Lastname content not exist in my email. Can someone help me?

1 Answer 1

1

You can try below code

{{if data.xfirstname}}First Name: {{var data.xfirstname}}{{else}}{{/if}}
{{if data.xlastname}}First Name: {{var data.xlastname}}{{else}}{{/if}}
10
  • thank you, I checked and is the same no data for xfirstname and xlastname
    – Robert
    Commented Jun 27, 2017 at 13:08
  • check updated answer Commented Jun 27, 2017 at 13:08
  • I see but is there any way to have only one if statement?
    – Robert
    Commented Jun 27, 2017 at 13:10
  • What you want to display? Commented Jun 27, 2017 at 13:20
  • I have two contacts forms, I search for a solution to change the email template for each form and I find only this solution
    – Robert
    Commented Jun 27, 2017 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.