cancel
Showing results for 
Search instead for 
Did you mean: 

Contact form error from the static block in the product page

Contact form error from the static block in the product page

Hello,
I have a problem with the contact form within the product pages.
I added a contact form in a static block, on the product page.
Should send an email with the url of the product, but it does only the first time, I'll explain better, if you go for the first time on the site and send the contact form, in the mail I get the correct url, if you continue browsing and send another contact form from another product page I always get the url of the previous product, when I delete the cache from the backend the problem is solved.
In addition, after sending the contact form you are redirected to the "contact us" page, but I would like the user to remain on the product page.

 

This is the code I added in "form.phtml":

    <?php
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
        $url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
        $path = $url->getPath();
    ?>
<input type="hidden" name="url" id="url" value="<?php echo $path; ?>" />

This is the full code of "form.phtml":

 <?php
    /**
     * Magento
     *
     * NOTICE OF LICENSE
     *
     * This source file is subject to the Academic Free License (AFL 3.0)
     * that is bundled with this package in the file LICENSE_AFL.txt.
     * It is also available through the world-wide-web at this URL:
     * http://opensource.org/licenses/afl-3.0.php
     * If you did not receive a copy of the license and are unable to
     * obtain it through the world-wide-web, please send an email
     * to license@magento.com so we can send you a copy immediately.
     *
     * DISCLAIMER
     *
     * Do not edit or add to this file if you wish to upgrade Magento to newer
     * versions in the future. If you wish to customize Magento for your
     * needs please refer to http://www.magento.com for more information.
     *
     * @category    design
     * @package     rwd_default
     * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
     * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
     */
    ?>
    <?php
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
        $url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
        $path = $url->getPath();
    ?>
    <div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
    <div class="page-title">
        <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
    </div>
    <form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" class="scaffold-form">
        <div class="fieldset">
            <h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
            <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
            <ul class="form-list">
                <li class="fields">
                    <div class="field">
                        <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
                        <div class="input-box">
                            <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                        </div>
                    </div>
                    <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="email" autocapitalize="off" autocorrect="off" spellcheck="false" />
                        </div>
                    </div>
                </li>
                <li>
                    <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
                    <div class="input-box">
                        <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="tel" />
                    </div>
                </li>
                <li class="wide">
                    <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
                    <div class="input-box">
                        <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="2" rows="2"></textarea>
                    </div>
                </li>
            </ul>
        </div>
        <div class="buttons-set">
            <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
            <input type="hidden" name="url" id="url" value="<?php echo $path; ?>" />
            <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
        </div>
    </form>
    <script type="text/javascript">
    //<![CDATA[
        var contactForm = new VarienForm('contactForm', true);
    //]]>
    </script>

This is the code I added in "contact_form.html":

Pagina: {{var data.url}}

This is the full code of "contact_form.html":

<!--@subject Contatto dal Form@-->
<!--@vars
{"var data.name":"Sender Name",
"var data.email":"Sender Email",
"var data.telephone":"Sender Telephone",
"var data.comment":"Comment"}
@-->
Nome: {{var data.name}}
Email: {{var data.email}}
Telefono: {{var data.telephone}}
Pagina: {{var data.url}}
Commento: {{var data.comment}}

This is the code I added in "static block":

<!--– CONTACT FORM –-->
{{block type="core/template" name="contactForm" form_action="/it/contacts/index/post" template="contacts/form.phtml"}}
<!--– END OF CONTACT FORM –-->

Can someone help me, please?