Jump to content

Send a friend module - how to add a field


CP00

Recommended Posts

  • 5 years later...

Hallo,
 
i wanna add a textarea for comment in send to friend form like following in "/themes/mytheme/modules/sendtoafriend/sendtoafriend-extra.tpl":

<p class="text">
<label for="friend_comment">{l s='Friend\'s Comment' mod='sendtoafriend'}</label>
<textarea style="width:100%" id="friend_comment" name="friend_comment" value="" /></textarea>
</p>

in "/modules/sendtoafriend/sendtoafriend.php":

$this->context->smarty->assign(array(
'stf_product' => $product,
'stf_product_cover' => (int)$product->id.'-'.(int)$image['id_image'],
'stf_secure_key' => $this->secure_key,
'stf_comment' => $_POST['friend_comment']
));

in "/themes/mytheme/modules/sendtoafriend/sendtoafriend_ajax.php":

...
else
{
$friendName = Tools::getValue('name');
$friendMail = Tools::getValue('email');
$id_product = Tools::getValue('id_product');
$friendComment = $_POST['friend_comment'];
}
 
...
 
$templateVars = array(
'{product}' => $product->name,
'{product_link}' => $productLink,
'{customer}' => $customer,
'{name}' => Tools::safeOutput($friendName),
'{friend_comment}' => $friendComment
);

in "/modules/sendtoafriend/mails/send_to_a_friend.html":

{friend_comment} ({$stf_comment})

My issue is, i don't get $_POST['friend_comment'] from "sendtoafriend-extra.tpl". The variable in the e-mail is empty.

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

I find the ajax part of sending data for 'send to a friend':

<script type="text/javascript">
{literal}
$('document').ready(function(){
	$('#send_friend_button').fancybox({
		'hideOnContentClick': false
	});

	$('#sendEmail').click(function(){
        
        var name = $('#friend_name').val();
        var email = $('#friend_email').val();
        var id_product = $('#id_product_comment_send').val();
		if (name && email && !isNaN(id_product))
		{
			$.ajax({
				{/literal}url: "{$module_dir}sendtoafriend_ajax.php",{literal}
				type: "POST",
				headers: {"cache-control": "no-cache"},
				data: {action: 'sendToMyFriend', secure_key: '{/literal}{$stf_secure_key}{literal}', name: name, email: email, id_product: id_product, test: test},{/literal}{literal}
				dataType: "json",
				success: function(result) {
					$.fancybox.close();
                    var msg = result ? "{/literal}{l s='Your e-mail has been sent successfully' mod='sendtoafriend'}{literal}" : "{/literal}{l s='Your e-mail could not be sent. Please check the e-mail address and try again.' mod='sendtoafriend'}{literal}";
                    var title = "{/literal}{l s='Send to a friend' mod='sendtoafriend'}{literal}";
                    fancyMsgBox(msg, title);
				}
			});
		}
		else
			$('#send_friend_form_error').text("{/literal}{l s='You did not fill required fields' mod='sendtoafriend' js=1}{literal}");
	});
});
{/literal}
</script>

This code is in '/module/sendtoafriend/sendtoafriend-extra.tpl' beginning line 26.

 

But the template in '/themes/mytheme/modules/sendtoafriend/sendtoafriend-extra.tpl' is using by prestashop. In '/themes' the code above doesn't exists. How prestashop sending the POST variables to the file sentoafriend_ajax.php with the template in themes folder ?? 

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

in /themes/js/modules/sendtoafriend/sentoafriend.js i found the code but not effects :(

 

$('#sendEmail').click(function(){
var name = $('#friend_name').val();
var email = $('#friend_email').val();
var f_comment = $("#friend_comment").val();

...

$.ajax({
url: baseDir + 'modules/sendtoafriend/sendtoafriend_ajax.php?rand=' + new Date().getTime(),
type: "POST",
headers: {"cache-control": "no-cache"},
data: {
action: 'sendToMyFriend', 
secure_key: stf_secure_key,
name: name, 
email: email, 
id_product: id_product,
stf_comment: 'OLE'
}

I can't post 'stf_comment' to 'sendtoafriend_ajax.php'. What is wrong ?

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

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...