[TASK] Formstyle

This commit is contained in:
Christian Seyfferth 2020-05-20 17:34:25 +02:00
parent 327b33a92e
commit f5f43b2173
3 changed files with 56 additions and 51 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* p01-contact - A simple contact forms manager.
*
@ -87,13 +88,13 @@ class P01contactField
}
// value blacklisted or not in whitelist
if ($reason = $this->isBlacklisted()) {
$this->error = 'field_'.$reason;
$this->error = 'field_' . $reason;
return false;
}
// not empty but not valid
if (!empty($this->value) && !$this->isValid()) {
$this->error = 'field_'.$this->type;
$this->error = 'field_' . $this->type;
return false;
}
@ -145,7 +146,7 @@ class P01contactField
'secret' => $this->form->config('recaptcha_secret_key'),
'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')) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
@ -204,30 +205,25 @@ class P01contactField
*/
public function html()
{
$id = 'p01-contact'.$this->form->getId().'_field'.$this->id;
$name = 'p01-contact_fields['.$this->id.']';
$id = 'p01-contact' . $this->form->getId() . '_field' . $this->id;
$name = 'p01-contact_fields[' . $this->id . ']';
$type = $this->getGeneralType();
$orig = $type != $this->type ? $this->type : '';
$value = $this->value;
$disabled = $this->locked ? ' disabled="disabled"' : '';
$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' : '';
$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) {
case 'textarea':
$html .= '<textarea id="'.$id.'" rows="10" ';
$html .= 'name="'.$name.'"'.$disabled.$required.$placeholder;
$html .= '>'.$value.'</textarea>';
$html .= '<textarea id="' . $id . '" rows="10" ';
$html .= 'class="materialize-textarea" ';
$html .= 'name="' . $name . '"' . $disabled . $required . $placeholder;
$html .= '>' . $value . '</textarea>';
break;
case 'captcha':
@ -238,7 +234,7 @@ class P01contactField
if (1 == $this->form->getId()) {
$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\">";
break;
@ -248,11 +244,11 @@ class P01contactField
foreach ($this->value as $i => $v) {
$selected = $this->isSelected($i) ? ' checked' : '';
$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 .= " type=\"{$type}\" class=\"{$type}\" name=\"{$name}\"";
$html .= " value=\"{$i}\"{$disabled}{$required}{$selected} />{$v}";
$html .= '</label>';
$html .= " value=\"{$i}\"{$disabled}{$required}{$selected} /><span>{$v}</span>";
$html .= '</label></p>';
}
$html .= '</div>';
@ -263,20 +259,21 @@ class P01contactField
$value = !empty($v) ? $v : 'Default';
$selected = $this->isSelected($i) ? ' selected="selected"' : '';
$html .= "<option id=\"{$id}_option{$i}\" value=\"{$i}\"{$selected}>";
$html .= $value.'</option>';
$html .= $value . '</option>';
}
$html .= '</select>';
break;
default:
$html .= '<input id="'.$id.'" ';
$html .= 'name="'.$name.'" type="'.$type.'" ';
$html .= 'value="'.$value.'"'.$disabled.$required.$placeholder.' />';
$html .= '<input id="' . $id . '" ';
$html .= 'name="' . $name . '" type="' . $type . '" ';
$html .= 'value="' . $value . '"' . $disabled . $required . $placeholder . ' />';
break;
}
$html .= '</div>';
if ('' === $is_single_option) {
$html .= $this->htmlLabel($id);
}
$html .= '</div>';
return $html;
@ -294,7 +291,7 @@ class P01contactField
$emphasis = $this->value ? 'font-weight:bold' : 'font-style:italic';
$html .= "\n\n\n";
$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 .= '</span></td>';
$html .= "\t\t";
@ -302,7 +299,7 @@ class P01contactField
// properties
$html .= '<td style="padding:.5em 1em; text-transform:lowercase; text-align:right; font-size:.875em; color:#888888; vertical-align: middle"><em>';
if (!$this->value) {
$html .= $this->form->lang('empty').' ';
$html .= $this->form->lang('empty') . ' ';
}
if ($this->title) {
$properties[] = $this->type;
@ -316,15 +313,15 @@ class P01contactField
}
}
if (count($properties)) {
$html .= '('.implode(', ', $properties).') ';
$html .= '(' . implode(', ', $properties) . ') ';
}
$html .= '#'.$this->id;
$html .= '#' . $this->id;
$html .= '</em></td></tr>';
$html .= "\n\n";
// value
if (!$this->value) {
return $html.'</table>';
return $html . '</table>';
}
$html .= '<tr><td colspan=2 style="padding:0">';
$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">';
$checkmark = '&#9744;';
}
$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 .= "</div>\n";
}
@ -371,17 +368,17 @@ class P01contactField
*/
private function htmlLabel($for)
{
$html .= '<label for="'.$for.'" class="doc">';
$html .= '<label for="' . $for . '" class="doc validate">';
if ($this->title) {
$html .= $this->title;
} else {
$html .= ucfirst($this->form->lang($this->type));
}
if ($this->description) {
$html .= ' <em class="description">'.$this->description.'</em>';
$html .= ' <em class="description">' . $this->description . '</em>';
}
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>';
@ -409,7 +406,7 @@ class P01contactField
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) {
return $out;
}
@ -417,9 +414,9 @@ function preint($arr, $return = false)
}
function predump($arr)
{
echo'<pre class="test" style="white-space:pre-wrap;">';
echo '<pre class="test" style="white-space:pre-wrap;">';
var_dump($arr);
echo'</pre>';
echo '</pre>';
}
function unset_r($a, $i)
{

View File

@ -1,4 +1,5 @@
<?php
/**
* p01-contact - A simple contact forms manager.
*
@ -88,8 +89,10 @@ class P01contactForm
*/
public function post()
{
if (empty($_POST['p01-contact_form'])
|| $_POST['p01-contact_form']['id'] != $this->id) {
if (
empty($_POST['p01-contact_form'])
|| $_POST['p01-contact_form']['id'] != $this->id
) {
return;
}
@ -160,9 +163,10 @@ class P01contactForm
public function html()
{
$html = '<div class="section">';
$html .= '<form action="'.PAGEURL.'#p01-contact'.$this->id.'" autocomplete="off" ';
$html .= 'id="p01-contact'.$this->id.'" class="p01-contact" method="post">';
$html .= '<form action="' . PAGEURL . '#p01-contact' . $this->id . '" autocomplete="off" ';
$html .= 'id="p01-contact' . $this->id . '" class="p01-contact" method="post">';
$html .= "<div class=\"row\">";
if ($this->status) {
$html .= $this->htmlStatus();
}
@ -173,10 +177,12 @@ class P01contactForm
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 .= '<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 class="submit" type="submit" value="'.$this->lang('send').'" /></div>';
$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 class="submit" type="submit" value="' . $this->lang('send') . '" /></div>';
}
$html .= '</div>';
$html .= '</form>';
$html .= '</div>';
@ -206,7 +212,7 @@ class P01contactForm
if ($post) {
list($headers, $targets, $subject, $text_content, $html_content) = $post;
$out .= '<h3>Virtually sent mail :</h3>';
$out .= '<pre>'.htmlspecialchars($headers).'</pre>';
$out .= '<pre>' . htmlspecialchars($headers) . '</pre>';
$out .= "<pre>Targets: {$targets}\nSubject: {$subject}</pre>";
$out .= "Text content : <pre>{$text_content}</pre>";
$out .= "HTML content : <div style=\"border:1px solid #ccc;\">{$html_content}</div>";
@ -272,7 +278,7 @@ class P01contactForm
$targets = implode(',', $this->targets);
$encoded_subject = $this->encodeHeader($subject);
$mime_boundary = '----'.md5(time());
$mime_boundary = '----' . md5(time());
$headers = $this->mailHeaders($name, $email, $mime_boundary);
$content = $this->mailContent($text, 'plain', $mime_boundary);
@ -525,7 +531,7 @@ class P01contactForm
{
$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)
{
$encoded_name = $this->encodeHeader($name);
$headers = "From: {$encoded_name} <no-reply@".SERVERNAME.">\n";
$headers = "From: {$encoded_name} <no-reply@" . SERVERNAME . ">\n";
if ($email) {
$headers .= "Reply-To: {$encoded_name} <{$email}>\n";
$headers .= "Return-Path: {$encoded_name} <{$email}>";
@ -548,7 +554,7 @@ class P01contactForm
$headers .= "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: multipart/alternative; boundary=\"{$mime_boundary}\"\n";
$headers .= 'X-Mailer: PHP/'.phpversion()."\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\n";
return $headers;
}
@ -568,7 +574,7 @@ class P01contactForm
$head .= "Content-Type: text/{$type}; charset=UTF-8\n";
$head .= "Content-Transfer-Encoding: 7bit\n\n";
return $head.$content."\n";
return $head . $content . "\n";
}
/**

View File

@ -1,3 +1,4 @@
/*
.p01-contact * {
box-sizing: border-box;
}
@ -98,3 +99,4 @@ textarea:invalid {
border-color: #ebccd1;
}
*/