[TASK] Formstyle
This commit is contained in:
parent
327b33a92e
commit
f5f43b2173
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* p01-contact - A simple contact forms manager.
|
* p01-contact - A simple contact forms manager.
|
||||||
*
|
*
|
||||||
@ -87,13 +88,13 @@ class P01contactField
|
|||||||
}
|
}
|
||||||
// value blacklisted or not in whitelist
|
// value blacklisted or not in whitelist
|
||||||
if ($reason = $this->isBlacklisted()) {
|
if ($reason = $this->isBlacklisted()) {
|
||||||
$this->error = 'field_'.$reason;
|
$this->error = 'field_' . $reason;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// not empty but not valid
|
// not empty but not valid
|
||||||
if (!empty($this->value) && !$this->isValid()) {
|
if (!empty($this->value) && !$this->isValid()) {
|
||||||
$this->error = 'field_'.$this->type;
|
$this->error = 'field_' . $this->type;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -145,7 +146,7 @@ class P01contactField
|
|||||||
'secret' => $this->form->config('recaptcha_secret_key'),
|
'secret' => $this->form->config('recaptcha_secret_key'),
|
||||||
'response' => $answer,
|
'response' => $answer,
|
||||||
];
|
];
|
||||||
$url = 'https://www.google.com/recaptcha/api/siteverify?'.http_build_query($params);
|
$url = 'https://www.google.com/recaptcha/api/siteverify?' . http_build_query($params);
|
||||||
if (function_exists('curl_version')) {
|
if (function_exists('curl_version')) {
|
||||||
$curl = curl_init($url);
|
$curl = curl_init($url);
|
||||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||||
@ -204,30 +205,25 @@ class P01contactField
|
|||||||
*/
|
*/
|
||||||
public function html()
|
public function html()
|
||||||
{
|
{
|
||||||
$id = 'p01-contact'.$this->form->getId().'_field'.$this->id;
|
$id = 'p01-contact' . $this->form->getId() . '_field' . $this->id;
|
||||||
$name = 'p01-contact_fields['.$this->id.']';
|
$name = 'p01-contact_fields[' . $this->id . ']';
|
||||||
$type = $this->getGeneralType();
|
$type = $this->getGeneralType();
|
||||||
$orig = $type != $this->type ? $this->type : '';
|
$orig = $type != $this->type ? $this->type : '';
|
||||||
$value = $this->value;
|
$value = $this->value;
|
||||||
$disabled = $this->locked ? ' disabled="disabled"' : '';
|
$disabled = $this->locked ? ' disabled="disabled"' : '';
|
||||||
$required = $this->required ? ' required ' : '';
|
$required = $this->required ? ' required ' : '';
|
||||||
$placeholder = $this->placeholder ? ' placeholder="'.$this->placeholder.'"' : '';
|
$placeholder = $this->placeholder ? ' placeholder="' . $this->placeholder . '"' : '';
|
||||||
|
|
||||||
$is_single_option = is_array($this->value) && 1 == count($this->value) ? 'inline' : '';
|
$is_single_option = is_array($this->value) && 1 == count($this->value) ? 'inline' : '';
|
||||||
$html = "<div class=\"row field {$is_single_option} {$type} {$orig} {$required}\">";
|
$html = "<div class=\"col s12 input-field {$is_single_option} {$type} {$orig} {$required}\">";
|
||||||
|
|
||||||
$html .= '<div class="col-sm-12 col-md-3">';
|
|
||||||
if ('' === $is_single_option) {
|
|
||||||
$html .= $this->htmlLabel($id);
|
|
||||||
}
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
$html .= '<div class="col-sm-12 col-md">';
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
$html .= '<textarea id="'.$id.'" rows="10" ';
|
$html .= '<textarea id="' . $id . '" rows="10" ';
|
||||||
$html .= 'name="'.$name.'"'.$disabled.$required.$placeholder;
|
$html .= 'class="materialize-textarea" ';
|
||||||
$html .= '>'.$value.'</textarea>';
|
$html .= 'name="' . $name . '"' . $disabled . $required . $placeholder;
|
||||||
|
$html .= '>' . $value . '</textarea>';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'captcha':
|
case 'captcha':
|
||||||
@ -238,7 +234,7 @@ class P01contactField
|
|||||||
if (1 == $this->form->getId()) {
|
if (1 == $this->form->getId()) {
|
||||||
$html .= '<script src="https://www.google.com/recaptcha/api.js"></script>';
|
$html .= '<script src="https://www.google.com/recaptcha/api.js"></script>';
|
||||||
}
|
}
|
||||||
$html .= '<div class="g-recaptcha" id="'.$id.'" data-sitekey="'.$key.'"></div>';
|
$html .= '<div class="g-recaptcha" id="' . $id . '" data-sitekey="' . $key . '"></div>';
|
||||||
$html .= "<input type=\"hidden\" id=\"{$id}\" name=\"{$name}\" value=\"trigger\">";
|
$html .= "<input type=\"hidden\" id=\"{$id}\" name=\"{$name}\" value=\"trigger\">";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -248,11 +244,11 @@ class P01contactField
|
|||||||
foreach ($this->value as $i => $v) {
|
foreach ($this->value as $i => $v) {
|
||||||
$selected = $this->isSelected($i) ? ' checked' : '';
|
$selected = $this->isSelected($i) ? ' checked' : '';
|
||||||
$v = !empty($v) ? $v : 'Default';
|
$v = !empty($v) ? $v : 'Default';
|
||||||
$html .= '<label class="option col-sm-12">';
|
$html .= '<p><label class="option col s12">';
|
||||||
$html .= "<input id=\"{$id}_option{$i}\"";
|
$html .= "<input id=\"{$id}_option{$i}\"";
|
||||||
$html .= " type=\"{$type}\" class=\"{$type}\" name=\"{$name}\"";
|
$html .= " type=\"{$type}\" class=\"{$type}\" name=\"{$name}\"";
|
||||||
$html .= " value=\"{$i}\"{$disabled}{$required}{$selected} />{$v}";
|
$html .= " value=\"{$i}\"{$disabled}{$required}{$selected} /><span>{$v}</span>";
|
||||||
$html .= '</label>';
|
$html .= '</label></p>';
|
||||||
}
|
}
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
@ -263,20 +259,21 @@ class P01contactField
|
|||||||
$value = !empty($v) ? $v : 'Default';
|
$value = !empty($v) ? $v : 'Default';
|
||||||
$selected = $this->isSelected($i) ? ' selected="selected"' : '';
|
$selected = $this->isSelected($i) ? ' selected="selected"' : '';
|
||||||
$html .= "<option id=\"{$id}_option{$i}\" value=\"{$i}\"{$selected}>";
|
$html .= "<option id=\"{$id}_option{$i}\" value=\"{$i}\"{$selected}>";
|
||||||
$html .= $value.'</option>';
|
$html .= $value . '</option>';
|
||||||
}
|
}
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$html .= '<input id="'.$id.'" ';
|
$html .= '<input id="' . $id . '" ';
|
||||||
$html .= 'name="'.$name.'" type="'.$type.'" ';
|
$html .= 'name="' . $name . '" type="' . $type . '" ';
|
||||||
$html .= 'value="'.$value.'"'.$disabled.$required.$placeholder.' />';
|
$html .= 'value="' . $value . '"' . $disabled . $required . $placeholder . ' />';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ('' === $is_single_option) {
|
||||||
$html .= '</div>';
|
$html .= $this->htmlLabel($id);
|
||||||
|
}
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
@ -294,7 +291,7 @@ class P01contactField
|
|||||||
$emphasis = $this->value ? 'font-weight:bold' : 'font-style:italic';
|
$emphasis = $this->value ? 'font-weight:bold' : 'font-style:italic';
|
||||||
$html .= "\n\n\n";
|
$html .= "\n\n\n";
|
||||||
$html .= '<tr style="background-color: #eeeeee">';
|
$html .= '<tr style="background-color: #eeeeee">';
|
||||||
$html .= '<td style="padding: .5em .75em"><span style="'.$emphasis.'">';
|
$html .= '<td style="padding: .5em .75em"><span style="' . $emphasis . '">';
|
||||||
$html .= $this->title ? $this->title : ucfirst($this->form->lang($this->type));
|
$html .= $this->title ? $this->title : ucfirst($this->form->lang($this->type));
|
||||||
$html .= '</span></td>';
|
$html .= '</span></td>';
|
||||||
$html .= "\t\t";
|
$html .= "\t\t";
|
||||||
@ -302,7 +299,7 @@ class P01contactField
|
|||||||
// properties
|
// properties
|
||||||
$html .= '<td style="padding:.5em 1em; text-transform:lowercase; text-align:right; font-size:.875em; color:#888888; vertical-align: middle"><em>';
|
$html .= '<td style="padding:.5em 1em; text-transform:lowercase; text-align:right; font-size:.875em; color:#888888; vertical-align: middle"><em>';
|
||||||
if (!$this->value) {
|
if (!$this->value) {
|
||||||
$html .= $this->form->lang('empty').' ';
|
$html .= $this->form->lang('empty') . ' ';
|
||||||
}
|
}
|
||||||
if ($this->title) {
|
if ($this->title) {
|
||||||
$properties[] = $this->type;
|
$properties[] = $this->type;
|
||||||
@ -316,15 +313,15 @@ class P01contactField
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($properties)) {
|
if (count($properties)) {
|
||||||
$html .= '('.implode(', ', $properties).') ';
|
$html .= '(' . implode(', ', $properties) . ') ';
|
||||||
}
|
}
|
||||||
$html .= '#'.$this->id;
|
$html .= '#' . $this->id;
|
||||||
$html .= '</em></td></tr>';
|
$html .= '</em></td></tr>';
|
||||||
$html .= "\n\n";
|
$html .= "\n\n";
|
||||||
|
|
||||||
// value
|
// value
|
||||||
if (!$this->value) {
|
if (!$this->value) {
|
||||||
return $html.'</table>';
|
return $html . '</table>';
|
||||||
}
|
}
|
||||||
$html .= '<tr><td colspan=2 style="padding:0">';
|
$html .= '<tr><td colspan=2 style="padding:0">';
|
||||||
$html .= '<div style="padding:.5em 1.5em;border:1px solid #ccc">';
|
$html .= '<div style="padding:.5em 1.5em;border:1px solid #ccc">';
|
||||||
@ -340,7 +337,7 @@ class P01contactField
|
|||||||
$html .= '<div style="color:#ccc; font-style:italic">';
|
$html .= '<div style="color:#ccc; font-style:italic">';
|
||||||
$checkmark = '☐';
|
$checkmark = '☐';
|
||||||
}
|
}
|
||||||
$html .= '<span style="font-size:1.5em; vertical-align:middle; margin-right:.5em; font-style:normal">'.$checkmark.'</span>';
|
$html .= '<span style="font-size:1.5em; vertical-align:middle; margin-right:.5em; font-style:normal">' . $checkmark . '</span>';
|
||||||
$html .= empty($v) ? 'Default' : $v;
|
$html .= empty($v) ? 'Default' : $v;
|
||||||
$html .= "</div>\n";
|
$html .= "</div>\n";
|
||||||
}
|
}
|
||||||
@ -371,17 +368,17 @@ class P01contactField
|
|||||||
*/
|
*/
|
||||||
private function htmlLabel($for)
|
private function htmlLabel($for)
|
||||||
{
|
{
|
||||||
$html .= '<label for="'.$for.'" class="doc">';
|
$html .= '<label for="' . $for . '" class="doc validate">';
|
||||||
if ($this->title) {
|
if ($this->title) {
|
||||||
$html .= $this->title;
|
$html .= $this->title;
|
||||||
} else {
|
} else {
|
||||||
$html .= ucfirst($this->form->lang($this->type));
|
$html .= ucfirst($this->form->lang($this->type));
|
||||||
}
|
}
|
||||||
if ($this->description) {
|
if ($this->description) {
|
||||||
$html .= ' <em class="description">'.$this->description.'</em>';
|
$html .= ' <em class="description">' . $this->description . '</em>';
|
||||||
}
|
}
|
||||||
if ($this->error) {
|
if ($this->error) {
|
||||||
$html .= ' <span class="error-msg">'.$this->form->lang($this->error).'</span>';
|
$html .= ' <span class="error-msg">' . $this->form->lang($this->error) . '</span>';
|
||||||
}
|
}
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
|
|
||||||
@ -409,7 +406,7 @@ class P01contactField
|
|||||||
|
|
||||||
function preint($arr, $return = false)
|
function preint($arr, $return = false)
|
||||||
{
|
{
|
||||||
$out = '<pre class="test" style="white-space:pre-wrap;">'.print_r(@$arr, true).'</pre>';
|
$out = '<pre class="test" style="white-space:pre-wrap;">' . print_r(@$arr, true) . '</pre>';
|
||||||
if ($return) {
|
if ($return) {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
@ -417,9 +414,9 @@ function preint($arr, $return = false)
|
|||||||
}
|
}
|
||||||
function predump($arr)
|
function predump($arr)
|
||||||
{
|
{
|
||||||
echo'<pre class="test" style="white-space:pre-wrap;">';
|
echo '<pre class="test" style="white-space:pre-wrap;">';
|
||||||
var_dump($arr);
|
var_dump($arr);
|
||||||
echo'</pre>';
|
echo '</pre>';
|
||||||
}
|
}
|
||||||
function unset_r($a, $i)
|
function unset_r($a, $i)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* p01-contact - A simple contact forms manager.
|
* p01-contact - A simple contact forms manager.
|
||||||
*
|
*
|
||||||
@ -88,8 +89,10 @@ class P01contactForm
|
|||||||
*/
|
*/
|
||||||
public function post()
|
public function post()
|
||||||
{
|
{
|
||||||
if (empty($_POST['p01-contact_form'])
|
if (
|
||||||
|| $_POST['p01-contact_form']['id'] != $this->id) {
|
empty($_POST['p01-contact_form'])
|
||||||
|
|| $_POST['p01-contact_form']['id'] != $this->id
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +163,10 @@ class P01contactForm
|
|||||||
public function html()
|
public function html()
|
||||||
{
|
{
|
||||||
$html = '<div class="section">';
|
$html = '<div class="section">';
|
||||||
$html .= '<form action="'.PAGEURL.'#p01-contact'.$this->id.'" autocomplete="off" ';
|
$html .= '<form action="' . PAGEURL . '#p01-contact' . $this->id . '" autocomplete="off" ';
|
||||||
$html .= 'id="p01-contact'.$this->id.'" class="p01-contact" method="post">';
|
$html .= 'id="p01-contact' . $this->id . '" class="p01-contact" method="post">';
|
||||||
|
|
||||||
|
$html .= "<div class=\"row\">";
|
||||||
if ($this->status) {
|
if ($this->status) {
|
||||||
$html .= $this->htmlStatus();
|
$html .= $this->htmlStatus();
|
||||||
}
|
}
|
||||||
@ -173,10 +177,12 @@ class P01contactForm
|
|||||||
if ($this->config('use_honeypot')) {
|
if ($this->config('use_honeypot')) {
|
||||||
$html .= '<input type="checkbox" name="p01-contact_fields[totally_legit]" value="1" style="display:none !important" tabindex="-1" autocomplete="false">';
|
$html .= '<input type="checkbox" name="p01-contact_fields[totally_legit]" value="1" style="display:none !important" tabindex="-1" autocomplete="false">';
|
||||||
}
|
}
|
||||||
$html .= '<div><input name="p01-contact_form[id]" type="hidden" value="'.$this->id.'" />';
|
$html .= '<div><input name="p01-contact_form[id]" type="hidden" value="' . $this->id . '" />';
|
||||||
$html .= '<input name="p01-contact_form[token]" type="hidden" value="'.$this->getToken().'" />';
|
$html .= '<input name="p01-contact_form[token]" type="hidden" value="' . $this->getToken() . '" />';
|
||||||
$html .= '<input class="submit" type="submit" value="'.$this->lang('send').'" /></div>';
|
$html .= '<input class="submit" type="submit" value="' . $this->lang('send') . '" /></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$html .= '</div>';
|
||||||
$html .= '</form>';
|
$html .= '</form>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
@ -206,7 +212,7 @@ class P01contactForm
|
|||||||
if ($post) {
|
if ($post) {
|
||||||
list($headers, $targets, $subject, $text_content, $html_content) = $post;
|
list($headers, $targets, $subject, $text_content, $html_content) = $post;
|
||||||
$out .= '<h3>Virtually sent mail :</h3>';
|
$out .= '<h3>Virtually sent mail :</h3>';
|
||||||
$out .= '<pre>'.htmlspecialchars($headers).'</pre>';
|
$out .= '<pre>' . htmlspecialchars($headers) . '</pre>';
|
||||||
$out .= "<pre>Targets: {$targets}\nSubject: {$subject}</pre>";
|
$out .= "<pre>Targets: {$targets}\nSubject: {$subject}</pre>";
|
||||||
$out .= "Text content : <pre>{$text_content}</pre>";
|
$out .= "Text content : <pre>{$text_content}</pre>";
|
||||||
$out .= "HTML content : <div style=\"border:1px solid #ccc;\">{$html_content}</div>";
|
$out .= "HTML content : <div style=\"border:1px solid #ccc;\">{$html_content}</div>";
|
||||||
@ -272,7 +278,7 @@ class P01contactForm
|
|||||||
$targets = implode(',', $this->targets);
|
$targets = implode(',', $this->targets);
|
||||||
$encoded_subject = $this->encodeHeader($subject);
|
$encoded_subject = $this->encodeHeader($subject);
|
||||||
|
|
||||||
$mime_boundary = '----'.md5(time());
|
$mime_boundary = '----' . md5(time());
|
||||||
$headers = $this->mailHeaders($name, $email, $mime_boundary);
|
$headers = $this->mailHeaders($name, $email, $mime_boundary);
|
||||||
|
|
||||||
$content = $this->mailContent($text, 'plain', $mime_boundary);
|
$content = $this->mailContent($text, 'plain', $mime_boundary);
|
||||||
@ -525,7 +531,7 @@ class P01contactForm
|
|||||||
{
|
{
|
||||||
$statusclass = $this->sent ? 'alert success' : 'alert failed';
|
$statusclass = $this->sent ? 'alert success' : 'alert failed';
|
||||||
|
|
||||||
return '<div class="'.$statusclass.'">'.$this->lang($this->status).'</div>';
|
return '<div class="' . $statusclass . '">' . $this->lang($this->status) . '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -540,7 +546,7 @@ class P01contactForm
|
|||||||
private function mailHeaders($name, $email, $mime_boundary)
|
private function mailHeaders($name, $email, $mime_boundary)
|
||||||
{
|
{
|
||||||
$encoded_name = $this->encodeHeader($name);
|
$encoded_name = $this->encodeHeader($name);
|
||||||
$headers = "From: {$encoded_name} <no-reply@".SERVERNAME.">\n";
|
$headers = "From: {$encoded_name} <no-reply@" . SERVERNAME . ">\n";
|
||||||
if ($email) {
|
if ($email) {
|
||||||
$headers .= "Reply-To: {$encoded_name} <{$email}>\n";
|
$headers .= "Reply-To: {$encoded_name} <{$email}>\n";
|
||||||
$headers .= "Return-Path: {$encoded_name} <{$email}>";
|
$headers .= "Return-Path: {$encoded_name} <{$email}>";
|
||||||
@ -548,7 +554,7 @@ class P01contactForm
|
|||||||
$headers .= "\n";
|
$headers .= "\n";
|
||||||
$headers .= "MIME-Version: 1.0\n";
|
$headers .= "MIME-Version: 1.0\n";
|
||||||
$headers .= "Content-type: multipart/alternative; boundary=\"{$mime_boundary}\"\n";
|
$headers .= "Content-type: multipart/alternative; boundary=\"{$mime_boundary}\"\n";
|
||||||
$headers .= 'X-Mailer: PHP/'.phpversion()."\n";
|
$headers .= 'X-Mailer: PHP/' . phpversion() . "\n";
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
@ -568,7 +574,7 @@ class P01contactForm
|
|||||||
$head .= "Content-Type: text/{$type}; charset=UTF-8\n";
|
$head .= "Content-Type: text/{$type}; charset=UTF-8\n";
|
||||||
$head .= "Content-Transfer-Encoding: 7bit\n\n";
|
$head .= "Content-Transfer-Encoding: 7bit\n\n";
|
||||||
|
|
||||||
return $head.$content."\n";
|
return $head . $content . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/*
|
||||||
.p01-contact * {
|
.p01-contact * {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
@ -98,3 +99,4 @@ textarea:invalid {
|
|||||||
border-color: #ebccd1;
|
border-color: #ebccd1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
Loading…
x
Reference in New Issue
Block a user