Jump to content

[SOLVED] Custom Form?


Guest

Recommended Posts

Hey everyone,

 

Was wondering what the best option for creating a custom form in a CMS page that sends to a selected email?

 

Is the best option going through a website that charges for form submissions >100 a month, or is there a way to achieve this within prestashop?

 

Thanks in advance,

 

 

Link to comment
Share on other sites

Hey vekia,

 

Thanks so much for the reply!

 

Yes, right now I have a custom CMS page setup and then link that on the tophorizontalmodule.

 

Is that the best way to go about this?

 

I'm not sure how to proceed.

 

Thanks!

 

 

Link to comment
Share on other sites

You can create form in cms.tpl file located in your theme (remember about if condition to check cms id! otherwise form will appear on each category page).

 

Then in CMS controller you can add php script to send mail

 

regards

  • Like 1
Link to comment
Share on other sites

Hey vekia,

 

Thanks for the reply! :) Much appreciated.

 

I understand the first part of your instructions, however I am a little lost on the second part.

 

EDIT: Trying to understand on my own. Will update.

 

Thanks,

 

 

Link to comment
Share on other sites

Okay so I have made some progress. I found two ways to achieve a duplicate of the contact-us form.

 

First was through your method vekia, which was to add into the cms.tpl file using a check cms id function.

 

Quote
<div class="rte{if $content_only} content_only{/if}">

{$cms->content}

{if $cms->id==7}

 

INSERT CODE FROM CONTACT-FORM.TPL

 

 

{/if}

</div>

 

However, I did not prefer this solution because of the URL generated with a CMS page.

 

I then also noted this solution I found by searching around.

 

I duplicated 3 files;

1) ~/contact-form.php --> ~/customization-form.php

2) ~/controllers/front/ContactController.php --> ~/controllers/front/CustomizationController.php

3) ~/themes/YOURTHEME/contact-form.tpl --> ~/themes/YOURTHEME/customization-form.php

 

Then in CustomizationController I edited line 27 to the following:

 

Quote
class CustomizationControllerCore extends FrontController

 

Then line 29 to:

 

Quote
public $php_self = 'customization';

 

And line 255 to:

 

Quote
$this->setTemplate(_PS_THEME_DIR_.'customization-form.tpl');

 

Now I am in the process of changing the form around. I am able to add forms into the tpl file in my theme direction, but I am unsure of how to have those fields from the form emailed to me once customers submit it.

 

Could anyone shine some light on that? I would really appreciate it.

 

For example, I can put this in the tpl file customization.tpl:

 

Quote
<p class="text">

<label>Dimensions</label>

<input type="text" id="dimensions" />

</p>

 

But I am unsure of how to modify the CustomizationController in order for that field to be included in the email that is sent to me.

 

I would really appreciate any help. :)

 

Thanks in advance,

 

 

Link to comment
Share on other sites

Hey guys,

 

I just figured out the solution to my problem so I thought I would post it here!

 

The first method I posted turned out to be the best.

 

In this case the second method was a good way to make a duplicate of the contact-form, however it is not very customizable for the PHP novice such as myself.

 

So using the first method I inserted my HTML form within the cms.tpl using:

 

{if $cms->id==7}{/if}

 

Then making sure to use form action="../themes/yourtheme/mail.php" within the beginning of the form and then within mail.php (or whatever you name it.

 

For example mine is:

 

<form action="../themes/yourtheme/mail.php" method="POST">

<p>Name</p> <input type="text" name="name">

<p>Email</p> <input type="text" name="email">

<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />

<input type="submit" value="Send"><input type="reset" value="Clear">

</form>

 

Then for my mail.php I included this;

 

$name = $_POST['name'];

$email = $_POST['email'];

$message = $_POST['message'];

$formcontent="From: $name \n Message: $message";

$recipient = "[email protected]";

$subject = "Contact Form";

$mailheader = "From: $email \r\n";

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

echo "Thank You!";

 

This enabled me to have it sent to a blank page with "Thank you!" and it would send the email.

 

But I wanted it to redirect you to a thank you page on the site, so I made a custom CMS page saying thank you and we will get back to you shortly using at the top of mail.php:

 

<?php header( 'Location: http://www.domain.co...ent/id-pagename' );

 

This will allow a nice redirect.

 

Anyways, hope this helps anyone else that is looking for this solution.

 

All the best,

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Hey turculetztz,

 

You need to edit "cms.tpl" in your theme folder and add mail.php in the root of your theme folder, not the root of your prestashop installation.

 

Try changing your form initial tag to:

 

<form action="../themes/yourtheme/mail.php" method="POST" enctype="multipart/form-data">

 

Although that shouldn't really make a difference.

 

Are you wrapping your form with {if $cms->id==7}<form></form>{/if} or whatever is the ID number of your CMS page is?

 

Best,

 

eggo

Link to comment
Share on other sites

That would be a great implementation! But unfortunately out of my realm.

 

I'm working on having an attachment that the customer can upload the server/be sent by email to us.

 

If I come to a solution I will post it here. I would appreciate if anyone else would be able to expand upon this to add the functionality if they have the expertise. :) If not, when I find the solution I will post it here!

 

Best,

 

 

Link to comment
Share on other sites

  • 1 month later...

roflymego, in the end I made a firebug capture on the original contact form that has the upload field, then a paste in cms.tpl

everything works great, for sure it's not the correct way but i don't care as long as she serve my purpose, also no need for mail.php

 

prestashop 1.5.4.1, my code:

 

 

<!-- custom form-->

 

{if $cms->id==9}

<div id="personalizat">

<form enctype="multipart/form-data" class="std" method="post" action="/ro/contact-us">

<fieldset>

<h3>trimitere mesaj</h3>

<p class="select">

<label for="id_contact">Subiect</label>

<select onchange="showElemFromSelect('id_contact', 'desc_contact')" name="id_contact" id="id_contact">

<option value="0">-- Alege --</option>

<option value="2">Customer service</option>

<option value="1">Webmaster</option>

</select>

</p>

<p class="desc_contact" id="desc_contact0"> </p>

<p style="display:none; margin-left:10px;" class="desc_contact" id="desc_contact2">

For any question about a product, an order

</p>

<p style="display:none; margin-left:10px;" class="desc_contact" id="desc_contact1">

If a technical problem occurs on this website

</p>

<p class="text">

<label for="email">Adresa de e-mail</label>

<input type="text" value="" name="from" id="email">

</p>

<p class="text">

<label for="fileUpload">Atașează fișier</label>

<input type="hidden" value="2000000" name="MAX_FILE_SIZE">

<input type="file" id="fileUpload" name="fileUpload">

</p>

<p class="textarea">

<label for="message">Mesaj</label>

<textarea cols="10" rows="15" name="message" id="message"></textarea>

</p>

<p class="submit">

<input type="submit" onclick="$(this).hide();" class="button_large" value="Trimite" id="submitMessage" name="submitMessage">

</p>

</fieldset>

</form>

</div>

<!-- end of custom form -->

Link to comment
Share on other sites

  • 6 months later...

Yea, thx, it's ok now with <form action="/themes/default/Mail.php" method="POST">

and mail.php there

 

I'm not yet familiar with some things:)

hi guys.

I did exactly what you said. and the form looks good within the CMS. but when I try to send an message using the form. it does not send. and gives me an 404 error message.

I set up the recipient email according to what you said.

please help, where I got it wrong?

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

 

 

i need this type of contact us page how can i creat this page ??

 

contact US form link>>>  www.theshop247.com/contact-us

 

simply but funcional for me :)

 

any idea of possible problems?

 

insert if...../if into the cms.tpl if you do not need to have pressed "CONTAC US" or "CUSTOMER SERVIS" button

 

<div class="rte{if $content_only} content_only{/if}">
{$cms->content}
 
{if $cms->id == 6} // 6 ->ID of CMS - contact us, change it if needed
        {Tools::redirect('index.php?controller=contact')} 
{/if}
 
</div>
Link to comment
Share on other sites

  • 4 months later...

Thanks!

But I don't duplicate contactblock, but i need create a new contactblock call this workus, because i need create a module for people job with us.

I want put a link in navbar near "contact us" and link open page with this form

I'm very confused :(

Link to comment
Share on other sites

  • 5 months later...

jjryeste, 

 

You could simply create a separate Contact category instead of "Webmaster" or "Customer Support" etc, and note the value of the new addition. Then from there edit your tpl file and make the option value ="#" the new number that has been assigned to the value you created. Make that the only option (in other words remove the foreach loop in the option html under subject heading) and even hide the subject heading altogether with display:none; if you wish. Make these edits in the tpl file for your new contact form.

 

Update for 1.6.x users, for creating a duplicate contact form the procedure is the same except for you only need to copy the controller and the theme tpl file. There is no contact.php in the home anymore.

 

Cheers!

Link to comment
Share on other sites

  • 1 month later...

Depends on if you used the CMS method (which is kind of a bit of a hacked up version which I really wouldn't recommend using) then it would be under the CMS id that you used for the tutorial. If you used the controller duplicate method then it will be under the new URL that you have to specify under SEO and URLs based on the new tpl file and controller.

 

Good luck! 

Link to comment
Share on other sites

Oh great. I got it. Its working the way you said it would. I am so amazed how you figured this out all on your own. Rather than having to purchase a new contact form, which my boss would not be willing to pay for, you gave a brilliant solution. Thanks buddy. :)

Link to comment
Share on other sites

Hi , I noticed that the form worked just fine but i have an error in other cms page. Does anyone have any idea what this error is and help me get rid of it. 

 

Notice: Undefined index: cms in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41

Notice: Trying to get property of non-object in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41

Notice: Trying to get property of non-object in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41

 

This is what line 41 looks like.

 

<?php if ($_smarty_tpl->tpl_vars['cms']->value->id==4){?>

Link to comment
Share on other sites

  • 2 months later...

Thank you for the example and good share. I am facing a problem, where I have two languages in my store, and I placed the mail.php file in the root, themes, and default-bootstrap directory as well. When the form submits, it redirects to mayDomainName.com/lang/mail.php and throws me 404 not found. How can I set the action="" to be relative to the lang?

 

Thanks

Link to comment
Share on other sites

  • 1 month later...

Hi. How to redirect after submit to the same page instead of some other page in header: location?

 

The solution for add information about product in the form

 

<form action="../themes/yourtheme/mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">

<input type="hidden" name="product" value="{$product->name|escape:'htmlall':'UTF-8'}">
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

 

 

and

 

$message = $_POST['message'];

$product = $_POST['product'];
$formcontent="From: $name \n About: $product \n Message: $message";

Edited by PipBoy2000 (see edit history)
Link to comment
Share on other sites

Hi. How to redirect after submit to the same page instead of some other page in header: location?

 

The solution for add information about product in the form

 

<form action="../themes/yourtheme/mail.php" method="POST">

<p>Name</p> <input type="text" name="name">

<p>Email</p> <input type="text" name="email">

<input type="hidden" name="product" value="{$product->name|escape:'htmlall':'UTF-8'}">

<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />

<input type="submit" value="Send"><input type="reset" value="Clear">

</form>

 

 

and

 

$message = $_POST['message'];

$product = $_POST['product'];

$formcontent="From: $name \n About: $product \n Message: $message";

Before 

$message = $_POST['message'];

 

Use this line

 

header('Location:http://UrlOfThePageYouWant'); 

It should redirect to whatever page you are after

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...