Skip to content

Commit 421b7d2

Browse files
Merge pull request #2 from joomdev/dev
Merging new features on Dev to Master
2 parents 577e50c + f2b0861 commit 421b7d2

File tree

19 files changed

+267
-53
lines changed

19 files changed

+267
-53
lines changed

assets/css/style.css

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forms/fielditem.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<option value="email">MOD_JDSCF_TYPE_EMAIL_LBL</option>
2828
<option value="number">MOD_JDSCF_TYPE_NUMBER_LBL</option>
2929
<option value="url">MOD_JDSCF_TYPE_URL_LBL</option>
30+
<option value="file">MOD_JDSCF_TYPE_FILE_LBL</option>
3031
</field>
3132
<field
3233
name="label"

helper.php

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @package JD Simple Contact Form
55
* @author JoomDev https://www.joomdev.com
6-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
6+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
77
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
88
*/
99
// no direct access
@@ -15,19 +15,19 @@ public static function renderForm($params, $module) {
1515
$fields = $params->get('fields', []);
1616
foreach ($fields as $field) {
1717
$field->id = \JFilterOutput::stringURLSafe('jdscf-' . $module->id . '-' . $field->name);
18-
self::renderField($field, $module);
18+
self::renderField($field, $module, $params);
1919
}
2020
}
2121

22-
public static function renderField($field, $module) {
22+
public static function renderField($field, $module, $params) {
2323
$label = new JLayoutFile('label', JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
2424
$field_layout = self::getFieldLayout($field->type);
2525
$input = new JLayoutFile('fields.' . $field_layout, JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
2626
$layout = new JLayoutFile('field', JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
2727
if ($field->type == 'checkbox') {
2828
$field->show_label = 0;
2929
}
30-
echo $layout->render(['field' => $field, 'label' => $label->render(['field' => $field]), 'input' => $input->render(['field' => $field, 'label' => self::getLabelText($field), 'module' => $module]), 'module' => $module]);
30+
echo $layout->render(['field' => $field, 'label' => $label->render(['field' => $field]), 'input' => $input->render(['field' => $field, 'label' => self::getLabelText($field), 'module' => $module, 'params' => $params]), 'module' => $module]);
3131
}
3232

3333
public static function getOptions($options) {
@@ -89,26 +89,69 @@ public static function submitForm($ajax = false) {
8989
$labels[$field->name] = ['label' => self::getLabelText($field), 'type' => $field->type];
9090
}
9191

92+
$cc_emails = [];
9293
$values = [];
9394
foreach ($jdscf as $name => $value) {
94-
$values[$name] = $value;
95+
if(is_array($value)) {
96+
if(isset($value['email'])) {
97+
$values[$name] = $value['email'];
98+
if(isset($value['cc']) && $value['cc'] == 1) {
99+
$cc_emails[] = $value['email'];
100+
}
101+
}
102+
} else {
103+
$values[$name] = $value;
104+
}
95105
}
96106

97-
98107
$contents = [];
108+
$attachments = [];
109+
$errors = [];
99110
foreach ($labels as $name => $fld) {
100111
$value = isset($values[$name]) ? $values[$name] : '';
101-
if ($fld['type'] == 'checkbox') {
112+
113+
if ($fld['type'] == 'checkboxes') {
114+
115+
$value = $_POST['jdscf'][$name]['cbs'];
116+
117+
if (is_array($value)) {
118+
$value = implode(', ', $value);
119+
} else {
120+
$value = $value;
121+
}
122+
}
123+
124+
if ($fld['type'] == 'checkbox') {
125+
$value = $_POST['jdscf'][$name]['cb'];
102126
if (is_array($value)) {
103127
$value = implode(',', $value);
128+
} else {
129+
$value = $value;
104130
}
105131
$value = empty($value) ? 'unchecked' : 'checked';
106132
}
133+
134+
if ($fld['type'] == 'file') {
135+
if(isset($_FILES['jdscf']['name'][$name])) {
136+
$value = $_FILES['jdscf']['name'][$name];
137+
$uploaded = self::uploadFile($_FILES['jdscf']['name'][$name], $_FILES['jdscf']['tmp_name'][$name]);
138+
//filetype error
139+
if(!empty($value)) {
140+
if(!$uploaded) {
141+
$errors[] = JText::_('MOD_JDSCF_UNSUPPORTED_FILE_ERROR');
142+
}
143+
}
144+
if(!empty($uploaded)) {
145+
$attachments[] = $uploaded;
146+
}
147+
}
148+
}
107149
if ($fld['type'] == 'textarea') {
108150
if ($value) {
109151
$value = nl2br($value);
110152
}
111153
}
154+
112155
$contents[] = [
113156
"value" => $value,
114157
"label" => $fld['label'],
@@ -167,7 +210,12 @@ public static function submitForm($ajax = false) {
167210
}
168211
// CC
169212
$cc = !empty($params->get('email_cc', '')) ? $params->get('email_cc') : '';
170-
$cc = explode(',', $cc);
213+
$cc = empty($cc) ? [] : explode(",", $cc);
214+
if(!empty($cc_emails)){
215+
$cc = array_merge($cc, $cc_emails);
216+
$cc = array_unique($cc);
217+
}
218+
171219
if (!empty($cc)) {
172220
$mailer->addCc($cc);
173221
}
@@ -180,7 +228,20 @@ public static function submitForm($ajax = false) {
180228
$mailer->isHtml(true);
181229
$mailer->Encoding = 'base64';
182230
$mailer->setBody($html);
183-
$send = $mailer->Send();
231+
foreach($attachments as $attachment){
232+
$mailer->addAttachment($attachment);
233+
}
234+
if(!empty($errors)) {
235+
$app = JFactory::getApplication();
236+
//showing all the validation errors
237+
foreach ($errors as $error) {
238+
$app->enqueueMessage(\JText::_($error), 'error');
239+
}
240+
}
241+
else {
242+
$send = $mailer->Send();
243+
}
244+
184245
if ($send !== true) {
185246
throw new \Exception(JText::_('MOD_JDSCFEMAIL_SEND_ERROR'));
186247
}
@@ -283,4 +344,49 @@ public static function getJS($moduleid) {
283344
return $GLOBALS['mod_jdscf_js_' . $moduleid];
284345
}
285346

347+
public static function isCCMail($field, $params){
348+
$sendcopy_email = $params->get('sendcopy_email', 0);
349+
$sendcopyemail_field = $params->get('sendcopyemail_field', '');
350+
$sendcopyemail_fields = explode(",", $sendcopyemail_field);
351+
if($sendcopy_email && !empty($sendcopyemail_fields) && in_array($field->name, $sendcopyemail_fields)){
352+
return true;
353+
}else{
354+
return false;
355+
}
356+
}
357+
358+
public static function uploadFile($name, $src) {
359+
jimport('joomla.filesystem.file');
360+
jimport('joomla.application.component.helper');
361+
362+
$fullFileName = JFile::stripExt($name);
363+
$filetype = JFile::getExt($name);
364+
$filename = JFile::makeSafe($fullFileName."_".mt_rand(10000000,99999999).".".$filetype);
365+
366+
$params = JComponentHelper::getParams('com_media');
367+
$allowable = array_map('trim', explode(',', $params->get('upload_extensions')));
368+
369+
if ($filetype == '' || $filetype == false || (!in_array($filetype, $allowable) ))
370+
{
371+
return false;
372+
}
373+
else
374+
{
375+
$tmppath = JPATH_SITE . '/tmp';
376+
if(!file_exists($tmppath.'/jdscf')){
377+
mkdir($tmppath.'/jdscf',0777);
378+
}
379+
$folder = md5(time().'-'.$filename.rand(0,99999));
380+
if(!file_exists($tmppath.'/jdscf/'.$folder)){
381+
mkdir($tmppath.'/jdscf/'.$folder,0777);
382+
}
383+
$dest = $tmppath.'/jdscf/'.$folder.'/'.$filename;
384+
385+
$return = null;
386+
if (JFile::upload($src, $dest)){
387+
$return = $dest;
388+
}
389+
return $return;
390+
}
391+
}
286392
}

language/en-GB/en-GB.mod_jdsimplecontactform.ini

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ MOD_JDSCF_EMAIL_BCC_DESC="BCC email address to recieve submissions. Use comma to
123123
MOD_JDSCF_EMAIL_TEMPLATE_LBL="Email Template"
124124
MOD_JDSCF_EMAIL_TEMPLATE_DESC="Select the email template, The <b>default</b> template lists all fields in the order they exist in <br><b>{field:label}: {field:value}</b></br> format."
125125

126+
MOD_JDSCF_SEND_COPY="Send Copy of Email"
127+
MOD_JDSCF_SEND_COPY_LBL_TITLE="Send me a copy"
128+
MOD_JDSCF_SEND_COPY_DESCRIPTION="Displays a checkbox for users to send a copy of email to themselves."
129+
130+
MOD_JDSCF_SEND_COPY_EMAIL_FIELD="Enter Email Field Name"
131+
MOD_JDSCF_SEND_COPY_LABEL="Enter Send Copy Label"
132+
133+
MOD_JDSCF_EMAIL_NAME="Enter name of email"
134+
MOD_JDSCF_EMAIL_NAME_DESCRIPTION="Name of email input field to send a copy to."
135+
126136
MOD_JDSCF_EMAIL_CUSTOM_TEMPLATE_LBL="Custom Email Template"
127137
MOD_JDSCF_EMAIL_CUSTOM_TEMPLATE_DESC="Enter your custom email template. You can use <b>{field:label}</b> for the field name, and <b>{field:value}</b> for user input value. Change <b>field</b> to the actual name of your input field."
128138

@@ -135,12 +145,15 @@ MOD_JDSCF_REDIRECT_DESC="Enter a URL to redirect users after submission. Leave b
135145
MOD_JDSCF_SUBMITBTN_CLASS_LBL="Submit button class"
136146
MOD_JDSCF_SUBMITBTN_CLASS_DESC=""
137147

148+
MOD_JDSCF_UNSUPPORTED_FILE_ERROR="Unsupported Filetype"
149+
MOD_JDSCF_AJAX_ERROR_ON_SUBMIT="Something went wrong! Please try again.";
150+
138151
MOD_JDSCF_DEFAULT_SUBJECT="New Submission%s"
139152

140153
MOD_JDSCF_TEXTAREA_ROWS_LBL="Rows"
141154
MOD_JDSCF_TEXTAREA_ROWS_DESC=""
142155

143-
MOD_JDSCF_THANKYOU_DEFAULT="Thank you."
156+
MOD_JDSCF_THANKYOU_DEFAULT="<div class='alert alert-success'>Thanks for reaching out!</div>"
144157
MOD_JDSCF_BAD_REQUEST="Bad Request"
145158
MOD_JDSCFEMAIL_SEND_ERROR="An error occurred while sending email."
146159
MOD_JDSCF_MODULE_NOT_FOUND="Module not found"

layouts/emails/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access

layouts/field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access

layouts/fields/calendar.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access
@@ -21,8 +21,27 @@
2121
$attrs[] = 'required';
2222
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
2323
}
24+
25+
$document = JFactory::getDocument();
26+
$style = 'label.calendar_icon {'
27+
. 'display: inherit;'
28+
. 'cursor: pointer;'
29+
. 'margin: 0px;'
30+
. 'border-radius: 0;'
31+
. '}';
32+
$document->addStyleDeclaration($style);
2433
?>
25-
<input type="text" name="jdscf[<?php echo $field->name; ?>]" class="form-control" <?php echo implode(' ', $attrs); ?> />
34+
35+
<div class="input-group mb-2">
36+
<input type="text" name="jdscf[<?php echo $field->name; ?>]" class="form-control" <?php echo implode(' ', $attrs); ?> autocomplete="off" />
37+
<label class="calendar_icon" for="<?php echo $field->id; ?>">
38+
<div class="input-group-prepend">
39+
<div class="input-group-text">
40+
<img height="16" width="16" src="data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgZm9jdXNhYmxlPSJmYWxzZSIgZGF0YS1wcmVmaXg9ImZhciIgZGF0YS1pY29uPSJjYWxlbmRhci1hbHQiIGNsYXNzPSJzdmctaW5saW5lLS1mYSBmYS1jYWxlbmRhci1hbHQgZmEtdy0xNCIgcm9sZT0iaW1nIiB4b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WMTJjMC02LjYgNS40LTEyIDEyLTEyaDQwYzYuNiAwIDEyIDUuNCAxMiAxMnY1Mmg0OGMyNi41IDAgNDggMjEuNSA0OCA0OHptLTQ4IDM0NlYxNjBINDh2Mjk4YzAgMy4zIDIuNyA2IDYgNmgzNDBjMy4zIDAgNi0yLjcgNi02eiI+PC9wYXRoPjwvc3ZnPg==" alt="Calendar">
41+
</div>
42+
</div>
43+
</label>
44+
</div>
2645

2746
<?php
2847
$js = 'var jdscf_picker_' . $module->id . ' = new Pikaday({'

layouts/fields/checkbox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access
@@ -16,7 +16,7 @@
1616
}
1717
?>
1818
<div class="form-check form-check-inline">
19-
<input class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][]" value="1" id="<?php echo $field->name; ?>" <?php echo implode(' ', $attrs); ?> />
19+
<input class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][cb]" value="1" id="<?php echo $field->name; ?>" <?php echo implode(' ', $attrs); ?> />
2020
<label class="form-check-label" for="<?php echo $field->name; ?>">
2121
<?php echo $label; ?>
2222
</label>

layouts/fields/checkboxes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access
@@ -20,7 +20,7 @@
2020
foreach ($options as $key => $option) {
2121
?>
2222
<div class="form-check<?php echo $optionslayout == 'inline' ? ' form-check-inline' : ''; ?>">
23-
<input data-parsley-errors-container="#<?php echo $field->name; ?>-errors" class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][]" value="<?php echo $option['value']; ?>" id="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>" <?php echo implode(' ', $attrs); ?> />
23+
<input data-parsley-errors-container="#<?php echo $field->name; ?>-errors" class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][cbs][]" value="<?php echo $option['value']; ?>" id="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>" <?php echo implode(' ', $attrs); ?> />
2424
<label class="form-check-label" for="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>">
2525
<?php echo $option['text']; ?>
2626
</label>

layouts/fields/file.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package JD Simple Contact Form
44
* @author JoomDev https://www.joomdev.com
5-
* @copyright Copyright (C) 2009 - 2018 JoomDev.
5+
* @copyright Copyright (C) 2009 - 2019 JoomDev.
66
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
77
*/
88
// no direct access
@@ -14,8 +14,42 @@
1414
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
1515
}
1616
$attrs[] = 'id="' . $field->name . '-file-input"';
17+
//fetching allowed types
18+
$params = JComponentHelper::getParams('com_media');
19+
$allowable = array_map('trim', explode(',', $params->get('upload_extensions')));
20+
$allowedMaxSize = $params->get('upload_maxsize');
21+
$document = JFactory::getDocument();
22+
$style = '.filesize-err {'
23+
. 'display: none;'
24+
. 'margin-top: 10px;'
25+
. '}';
26+
$document->addStyleDeclaration($style);
1727
?>
1828
<div class="custom-file">
19-
<input type="file" name="jdscf[<?php echo $field->name; ?>]" class="custom-file-input" <?php echo implode(' ', $attrs); ?>>
29+
<input id="<?php echo $field->name; ?>-<?php echo $module->id; ?>" accept="<?php foreach ($allowable as $type) { echo ".".$type.","; } ?>" type="file" name="jdscf[<?php echo $field->name; ?>]" class="custom-file-input" <?php echo implode(' ', $attrs); ?>>
2030
<label class="custom-file-label" for="<?php echo $field->name; ?>-file-input"><?php echo JText::_('MOD_JDSCF_FILE_BTN_LBL'); ?></label>
21-
</div>
31+
</div>
32+
33+
<div class="filesize-err filesize-error-<?php echo $field->name; ?>-<?php echo $module->id; ?> alert alert-danger alert-dismissable">
34+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
35+
File size is too big!
36+
</div>
37+
38+
39+
<?php
40+
// File size validation
41+
$js = 'var uploadField_'.$field->name.' = document.getElementById("' . $field->name . '-' .$module->id .'");';
42+
$js .= 'uploadField_' . $field->name .'.onchange = function() {';
43+
$js .= 'var fileSizeBytes = this.files[0].size;';
44+
// $js .= 'var i = parseInt(Math.floor(Math.log(fileSizeBytes) / Math.log(1024)));';
45+
// $js .= 'var fileSizeMb = parseFloat(Math.round(fileSizeBytes / Math.pow(1024, i), 2));';
46+
$js .= 'var filesizeMb = fileSizeBytes/1024/1024;';
47+
48+
$js .= 'if(filesizeMb > ' . $allowedMaxSize .'){';
49+
$js .= 'uploadField_'.$field->name.'.value = "";';
50+
$js .= 'jQuery(".filesize-error-' . $field->name . '-' . $module->id . '").show();';
51+
$js .= '}';
52+
$js .= '};';
53+
54+
ModJDSimpleContactFormHelper::addJS($js, $module->id);
55+
?>

0 commit comments

Comments
 (0)