Skip to content

Commit

Permalink
[-] MO sendtoafriend: The method used to check all required input fie…
Browse files Browse the repository at this point in the history
…lds could lead to errors
  • Loading branch information
fchellypresta committed Sep 27, 2013
1 parent 6449ecf commit 9d94337
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
18 changes: 6 additions & 12 deletions modules/sendtoafriend/sendtoafriend-extra.tpl
Expand Up @@ -31,23 +31,17 @@ $('document').ready(function(){
});
$('#sendEmail').click(function(){
var datas = [];
$('#send_friend_form_content').find(':input').each(function(index){
var o = {};
o.key = $(this).attr('name');
o.value = $(this).val();
if (o.value != '')
datas.push(o);
});
if (datas.length >= 3)
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}', friend: unescape(JSON.stringify(datas).replace(/\\u/g, '%u'))},{/literal}{literal}
data: {action: 'sendToMyFriend', secure_key: '{/literal}{$stf_secure_key}{literal}', name: name, email: email, id_product: id_product},{/literal}{literal}
dataType: "json",
success: function(result) {
$.fancybox.close();
Expand Down
16 changes: 3 additions & 13 deletions modules/sendtoafriend/sendtoafriend_ajax.php
Expand Up @@ -33,19 +33,9 @@

if (Tools::getValue('action') == 'sendToMyFriend' && Tools::getValue('secure_key') == $module->secure_key)
{
$friend_infos = Tools::jsonDecode(Tools::getValue('friend'));
$friendName = "";
$friendMail = "";
$id_product = null;
foreach ($friend_infos as $entry)
{
if ($entry->key == "friend_name")
$friendName = $entry->value;
else if ($entry->key == "friend_email")
$friendMail = $entry->value;
else if ($entry->key == "id_product")
$id_product = $entry->value;
}
$friendName = Tools::getValue('name');
$friendMail = Tools::getValue('email');
$id_product = Tools::getValue('id_product');
if (!$friendName || !$friendMail || !$id_product)
die('0');

Expand Down

0 comments on commit 9d94337

Please sign in to comment.