Magento Forum

Page 1 of 3
Contact form on a CMS page
 
Hoena
Jr. Member
 
Total Posts:  10
Joined:  2007-09-04
 

Hi!

I use this code to “import” the contact form on to a CMS page.

{{block type="core/template" name="contactForm" template="contacts/form.phtml"}}

the submit action is /contacts/index/post and redirect to /contacts/index/

But my CMS page is /kotakta-oss/

so how to make it go back to the /kontakta-oss/ page after submit the form?

or is there some other solution to manipulate the contact page from the adminsystem?

 
Magento Community Magento Community
Magento Community
Magento Community
 
wdchoi
Jr. Member
 
Total Posts:  20
Joined:  2008-11-17
 

Hi Hoena.

In the Mage/Contacts/controllers/IndexController.php file, you will find the postAction (which is called by your /contacts/index/post url). In it, you will find in several places the call to the method “_redirect(’*/*/’);” This is the method that redirects you at the end of the Post process towards /contacts/index. You could change it to “_redirect(’/kontacta-oss/index’)” if you want to.

But I prefer to tell you it’s better not to change the core/Mage code… Then, you’ll have to do what I wrote above, but in a controller-overriding manner. You have several topics explaining how to do that.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hoena
Jr. Member
 
Total Posts:  10
Joined:  2007-09-04
 
azn_david - 27 November 2008 05:33 AM

Hi Hoena.

In the Mage/Contacts/controllers/IndexController.php file, you will find the postAction (which is called by your /contacts/index/post url). In it, you will find in several places the call to the method “_redirect(’*/*/’);” This is the method that redirects you at the end of the Post process towards /contacts/index. You could change it to “_redirect(’/kontacta-oss/index’)” if you want to.

But I prefer to tell you it’s better not to change the core/Mage code… Then, you’ll have to do what I wrote above, but in a controller-overriding manner. You have several topics explaining how to do that.

Some more problems.

1. Can’t figure out how to make a controller overriding by following the wiki page.
http://www.magentocommerce.com/wiki/how_to_overload_a_controller#create_your_module_folders_and_files

2. I change the “core mage” file and can send mail but the statsus message doesn’t work.

3. I try to make a static block instead with the contact text and put the block into the form.phtml or in the contact.xml. This work too but the page have no breadcrumbs.

How to fix this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
wdchoi
Jr. Member
 
Total Posts:  20
Joined:  2008-11-17
 

Hi Hoena.

I’d like to answer all of your questions, but that would not be right. I mean we need to capitalize answers so that everybody can see these forum topics and learn from them.

So, if your first problem has been solved, please put [SOLVED] in front of its title. As for the other questions, make other topics in the right categories.

And for your first question, go see http://www.magentocommerce.com/boards/viewthread/15914/, that may help.

David

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pagayo
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2008-09-07
Netherlands
 

You could also try this. We use it in a category. That cat is now our contact form. ( -> Catalog -> Manage category -> Description ) Change the Display mode in “static block only” And name the category “Contact form”, or what ever name you want.

<h4>Contactformulier</h4>
<
div class="page-head">
</
div>

<
div class="clear">
                </
div> <form id="contactForm" method="post" action="/index/post/">
    <
fieldset class="group-select">
        <
ul>
        <
li>
 <
div class="input-box">
                    <
label for="name">Naam <span class="required">*</span></label><br/>
                    <
input name="name" id="name" title="Name" value="" class="required-entry input-text" type="text"/>
                </
div>

                <
div class="input-box">
                    <
label for="email">Email <span class="required">*</span></label><br/>
                    <
input name="email" id="email" title="Email" value="" class="required-entry input-text validate-email" type="text"/>
                </
div>

                <
div class="input-box">
                    <
label for="street">Straat Huisnummer <span class="required">*</span></label><br/>
                    <
input name="street" id="street" title="Street" value="" class="required-entry input-text" type="text"/>
                </
div>

                <
div class="input-box">
                    <
label for="city">Plaatsnaam <span class="required">*</span></label><br/>
                    <
input name="city" id="city" title="Email" value="" class="required-entry input-text" type="text"/>
                </
div>

                <
div class="input-box">

                    <
label for="po">Postcode <span class="required">*</span></label><br/>
                    <
input name="po" id="po" title="po" value="" class="required-entry input-text" type="text"/>
                </
div>

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

                <
div class="input-box">
                    <
label for="telephone">Telefoon </label><br />

                    <
input name="telephone" id="telephone" title="Telephone" value="" class="input-text" type="text"/>
                </
div>

                <
div class="input-box">
                    <
label for="website">Website URL</label><br />
                    <
input name="website" id="website" title="Website" value="" class="input-text" type="text"/>
                </
div>

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

                <
div class="input-box">
                    <
label for="comment">Commentaar </label><br />
                    <
textarea name="comment" id="comment" title="Comment" class="input-text" style="height:150px;width:525px;" cols="50" rows="5"></textarea>
                </
div>
                </
li>
                </
ul>
    </
fieldset>

    <
div class="button-set">
        <
class="required">* Verplichte velden</p>
        <
button class="form-button" type="submit"><span>Verstuur</span></button>
    </
div>
</
form>
<
script type="text/javascript">
    var 
contactForm = new VarienForm('contactForm'true);
</script>    
</div>

You must also change the contact_form.html. ( /app/locale/nl_NL/template/email )

<!--@subject Contact Form@-->
Pagayo customerquestion from site
----------------------------------------------------

{{var data.name}}

{{var data
.street}}
{{var data
.po}} {{var data.city}}

{{var data
.telephone}}

{{var data
.email}}
{{var data
.website}}

----------------------------------------------------

Question customer:

{{var data.comment}}

If you want a different return URL you should change

action="http://www.pagayo.nl/site/nl/contacts/index/post/"
in the code above.

I hope this helps someone

 
Magento Community Magento Community
Magento Community
Magento Community
 
lb336603
Jr. Member
 
Total Posts:  16
Joined:  2009-03-07
 

Paul,

Great advice! I found your step-by-step answer very approachable. I am still fiddling with getting the confirmation message to show, but otherwise, thanks to you, my contact form is running smoothly!

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonpday
Member
 
Avatar
Total Posts:  44
Joined:  2008-07-20
Adelaide, Australia
 

Please be very careful changing the core php files, it means that you will break your installation when you upgrade.  always take a copy of the file and place it in the /app/code/local folder with the same subfolder path.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmcmullin
Jr. Member
 
Total Posts:  7
Joined:  2009-08-11
 
Paul Hachmang - 05 July 2009 05:59 AM

4:
Make confirmation message show up:
Go to /app/design/frontend/default/yourstore/template/contacts/form.phtml and replace line 28:

<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
with:
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>

This last step is not working for me. Everything else is working but I’m not seeing any status messages (on the page to which I’m redirecting). In my case, this is a product view page. Would that make any difference? Is the session emptied for some reason upon redirect?
All I’m getting is the string “messages”. I’m using the following (in my controller postAction method) to do the redirect:

$this->_redirectReferer($_POST['produrl']);

So close...Any thoughts

Cheers,
J

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ed83
Jr. Member
 
Total Posts:  11
Joined:  2009-04-21
Vlissingen, NL
 

I have the same problems here, I’m not seeing any status messages.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmcmullin
Jr. Member
 
Total Posts:  7
Joined:  2009-08-11
 

I managed to do this eventually by setting the session save path before calling session_start:

session_save_path(’/home/yourdomain/public_html/var/session’);
session_name(’frontend’);
session_start();

My issue seemed to be that I was creating session files in 2 locations - one in the default location (from php.ini) and once in the session folder (/var/session) and the contents of these files differed. Upon redirect (for me that was back to the Product view page), I was picking up the wrong session (wrong session file) which didn’t have my status messages in it - they were in the other session file (which confusingly even had the same ID).

Hope this helps

J

 
Magento Community Magento Community
Magento Community
Magento Community
 
sisieko
Member
 
Avatar
Total Posts:  62
Joined:  2009-09-23
nyc
 
azn_david - 27 November 2008 05:33 AM

Hi Hoena.

In the Mage/Contacts/controllers/IndexController.php file, you will find the postAction (which is called by your /contacts/index/post url). In it, you will find in several places the call to the method “_redirect(’*/*/’);” This is the method that redirects you at the end of the Post process towards /contacts/index. You could change it to “_redirect(’/kontacta-oss/index’)” if you want to.

But I prefer to tell you it’s better not to change the core/Mage code… Then, you’ll have to do what I wrote above, but in a controller-overriding manner. You have several topics explaining how to do that.

Hi, I am having this redirect problem, perhaps you or someone here can help me.

I have included my contact form in two different cms pages. I’d like the redirect to the page it was on! Say if it was on the Customer Service cms page then it should stay there and simply show a “submitted confirmation message”. And if it was on the Contact us page, then it should stay there and simply show message. How do i make it possible.

My form doesn’t even respond at all when i hit submit.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jez_p
Jr. Member
 
Total Posts:  15
Joined:  2010-01-20
 

For anyone having problems getting their form to work, these instructions work:

http://www.casualcommerce.com/2009/03/magento-notes-fix-for-adding-contact-form-in-cms-pages/

 
Magento Community Magento Community
Magento Community
Magento Community
 
mafareed
Jr. Member
 
Total Posts:  11
Joined:  2010-04-28
 

Thanks azn_david and H&O;. Your solution worked great for me. You guys are life savers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Alex Leonard
Member
 
Total Posts:  43
Joined:  2010-02-03
 

I think this is nearly the straw that broke the camel’s back.

I was pretty much set to go live today and was finalising my list of tweaks and corrections and I came across the contact form not working issue which I’d left to the end as I, wrongly, assumed it would be a simple thing to work out.

How in the name of all that’s holy could a contact form be so complicated. I’ve got a ridiculous number of tabs open and am still no closer. My form works if I change my form action to:

<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">

but when I submit the form I get taken to that URL and only get redirected to /contacts/index instead of the CMS page on which I had added the contact form in the first place - so none of the other content of that page appears. I definitely do not want to go messing with core hacking, I learnt to avoid that a long time ago. I tried just making my topLinks “Contact Us” link to /contacts/index/ but of course none of my non-form page content shows up. I worked out that I could just manually hand-code the content into /contacts/form.phtml but that seems to defeat the point of a CMS and my client will wonder. I know I could include a static block at the top of that page but noticed that my breadcumbs functionality is cocked when using /contacts/index/, again I could just manually hand code the breadcrumbs in. I’ve even considered just dumping the form.phtml behaviour, bypassing Magento’s email system and just writing my own PHP script that actions to self and if isset a hidden POST field saying the form has been submitted then mail() the results.

But seriously, what the hell has made this simple contact form so complicated. This has most definitely nearly cracked me after a few weeks of intense confusion. Every time I think I have a handle on what’s going on something comes up that evaporates 6 hours of my time.

I’m very tired.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Alex Leonard
Member
 
Total Posts:  43
Joined:  2010-02-03
 

So I’ve hacked it into a just about acceptable thing. User submits form. Between contacts.xml and form.phtml which is called due to lack of proper redirection I have set another static block to be called, in which I’ve duplicated the content of the pre-form CMS page content. I had already tried to work out calling the CMS page content directly in form.phtml but gave up after 20 minutes of searching in circles.

So anyway, user submits form and are brought to a page where breadcrumbs disappear as they weren’t working anyway, and my client has to be informed that if they want to change their contact us intro text, they have to change it in the CMS page and a static block.

I no longer care as it’s 3.40am.

 
Magento Community Magento Community
Magento Community
Magento Community
 
deepak11
Member
 
Total Posts:  34
Joined:  2010-06-05
 

I have also face the same problem,this is really a redicules thing to do as it looks simple,i got some idea,after changing the url in action of from but still finding the bredcrumb after posting from can you tell me how to find this

can you tell me

\"I have set another static block to be called, in which I’ve duplicated the content of the pre-form CMS page \”

what exactly mean this?lar

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3