Commit f8440a92 authored by Simonas's avatar Simonas

in progress

parent 9f8d8242
......@@ -120,8 +120,8 @@ Can't share C drive
- `docker exec -it dev-biuro-nginx sh`
- `docker exec -it dev-biuro-wordpress bash`
- `docker exec -it dev-biuro-mysql bash`
- `mysql -uroot -pIiIjnsLi2wR9i1kWVbVpUAzP --default-character-set=utf8`
- `use wordpress;`
- `mysql -uroot -p'q@z!z29AO5rpzMjsDhjnFKyF' --default-character-set=utf8`
- `use dev_biuro;`
- `show tables;`
- `use information_schema;`
......
......@@ -75,7 +75,7 @@ services:
- '80:80'
- '443:443'
volumes:
- ./nginx/.htpasswd:/etc/nginx/.htpasswd
# - ./nginx/.htpasswd:/etc/nginx/.htpasswd
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/h5bp:/etc/nginx/h5bp
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
......
......@@ -40,6 +40,10 @@ class Biuro_Contacts_Public {
*/
private $version;
const fields = [
'employees-quick' => ['name', 'phone', 'email', 'agree', 'city', 'comment', 'cv']
];
/**
* Initialize the class and set its properties.
*
......@@ -227,6 +231,156 @@ class Biuro_Contacts_Public {
) + $dir;
}
public static function delete_transients( $str ) {
foreach (static::fields[$str] as $key) {
delete_transient($str . '--' . $key . '-value');
delete_transient($str . '--' . $key . '-status');
delete_transient($str . '--' . $key . '-message');
}
}
public static function validate( $str, $key, $value, $post ) {
$success = ['status' => 'success', 'message' => ''];
$required = ['status' => 'error', 'message' => 'This field is required'];
if ($str == 'employees-quick'):
switch($key) {
case 'name':
if (!$value):
return $required;
endif;
$arr = explode(' ', $value);
if (count($arr) < 2):
return [
'status' => 'warning',
'message' => 'Name and surname are required'
];
else:
return $success;
endif;
case 'phone':
if (!$value && !is_email($post['email'])):
return [
'status' => 'error',
'message' => 'Phone or email field is required'
];
endif;
if (!$value):
return [
'status' => '',
'message' => ''
];
endif;
return $success;
case 'email':
if (!$post['phone'] && !$value):
return [
'status' => 'error',
'message' => 'Email or phone field is required'
];
endif;
if (!$post['phone'] && !is_email($value)):
return [
'status' => 'warning',
'message' => 'Email format is incorrect'
];
else:
if (!$value):
return [
'status' => '',
'message' => ''
];
endif;
return $success;
endif;
case 'agree':
if ($value != 1):
return [
'status' => 'error',
'message' => 'You have to agree with conditions'
];
endif;
return $success;
}
endif;
return ;
}
public static function getValue( $key, $value ) {
switch($key) {
case 'name':
case 'phone':
case 'agree':
case 'city':
return sanitize_text_field($value);
case 'email':
return sanitize_email($value);
case 'comment':
return sanitize_textarea_field($value);
case 'cv':
return sanitize_file_name($value);
}
return '';
}
public static function set_transients( $str, $post ) {
// set_transient( 'employees-quick--name-value', $_POST['name'] );
// set_transient( 'employees-quick--name-status', 'success' );
// set_transient( 'employees-quick--name-message', '' );
// set_transient( 'employees-quick--phone-value', $_POST['phone'] );
// set_transient( 'employees-quick--phone-status', 'error' );
// set_transient( 'employees-quick--phone-message', 'Phone or email field is required' );
// set_transient( 'employees-quick--email-value', $_POST['email'] );
// set_transient( 'employees-quick--email-status', 'error' );
// set_transient( 'employees-quick--email-message', 'Email or phone field is required' );
// set_transient( 'employees-quick--agree-value', $_POST['agree'] );
// set_transient( 'employees-quick--agree-status', 'error' );
// set_transient( 'employees-quick--agree-message', 'You have to agree with conditions' );
// set_transient( 'employees-quick--city-value', $_POST['city'] );
// set_transient( 'employees-quick--city-status', 'warning' );
// set_transient( 'employees-quick--city-message', 'You have to agree with conditions' );
// set_transient( 'employees-quick--comment-value', $_POST['comment'] );
// set_transient( 'employees-quick--comment-status', 'warning' );
// set_transient( 'employees-quick--comment-message', 'You have to agree with conditions' );
// set_transient( 'employees-quick--cv-value', $_POST['cv'] );
// set_transient( 'employees-quick--cv-status', 'warning' );
// set_transient( 'employees-quick--cv-message', 'You have to agree with conditions' );
foreach (static::fields[$str] as $key) {
$value = static::getValue($key, $post[$key]);
$validation = static::validate($str, $key, $value, $post);
set_transient($str . '--' . $key . '-value', $value);
set_transient($str . '--' . $key . '-status', $validation['status']);
set_transient($str . '--' . $key . '-message', $validation['message']);
}
}
/**
* Processes shortcode biuro-contacts--employees
......@@ -236,29 +390,16 @@ class Biuro_Contacts_Public {
* @return mixed $output Output of the buffer
*/
public function employees_quick_form( $attr = array() ) {
// $args = shortcode_atts(
// array(
// 'arg1' => 'arg1',
// 'arg2' => 'arg2',
// ),
// $atts
// );
// $response = false;
ob_start();
// if ( isset( $_POST['submit'] ) ) :
// $response = true;
// endif;
include_once('partials/biuro-contacts-public--employees-quick.php');
$output = ob_get_contents();
ob_end_clean();
static::delete_transients('employees-quick');
return $output;
} // employees_form()
......@@ -274,8 +415,13 @@ class Biuro_Contacts_Public {
exit;
}
debug($_POST); //$_POST variables should be accessible now
// set_transient( 'employees-quick--status', '' );
// set_transient( 'employees-quick--message', '' );
static::set_transients('employees-quick', $_POST);
wp_redirect( $referer );
exit;
// /*
// * May prehandle file upload
......
......@@ -18,44 +18,57 @@
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?>
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data" class="c-form">
<?php
$nameValue = get_transient( 'employees-quick--name-value' );
$nameStatus = get_transient( 'employees-quick--name-status' );
$nameMessage = get_transient( 'employees-quick--name-message' );
?>
<div class="c-form--row">
<label class="c-form--label" for="form-name">Name, Surname*</label>
<div class="c-form--input-wrap">
<input type="text" class="c-form--input <?php if ($response) { echo 'c-form--input--error'; } ?>" id="form-name" name="name" value="">
<input type="text" class="c-form--input <?php if ($nameStatus) { echo "c-form--input--$nameStatus"; } ?>" id="form-name" name="name" value="<?php echo $nameValue; ?>">
</div>
<?php if ($response): ?>
<div class="c-form--validation-error">
Name and Surname is required
<?php if ($nameMessage): ?>
<div class="c-form--validation-<?php echo $nameStatus; ?>">
<?php echo $nameMessage; ?>
</div>
<?php endif; ?>
</div><!-- .c-form--row -->
<?php
$phoneValue = get_transient( 'employees-quick--phone-value' );
$phoneStatus = get_transient( 'employees-quick--phone-status' );
$phoneMessage = get_transient( 'employees-quick--phone-message' );
?>
<div class="c-form--row">
<label class="c-form--label" for="form-phone">Phone no.*</label>
<div class="c-form--input-wrap">
<input type="tel" class="c-form--input <?php if ($response) { echo 'c-form--input--error'; } ?>" id="form-phone" name="phone" value="">
<input type="tel" class="c-form--input <?php if ($phoneStatus) { echo "c-form--input--$phoneStatus"; } ?>" id="form-phone" name="phone" value="<?php echo $phoneValue; ?>">
</div>
<?php if ($response): ?>
<div class="c-form--validation-error">
Phone number is required
<?php if ($phoneMessage): ?>
<div class="c-form--validation-<?php echo $phoneStatus; ?>">
<?php echo $phoneMessage; ?>
</div>
<?php endif; ?>
</div><!-- .c-form--row -->
<?php
$emailValue = get_transient( 'employees-quick--email-value' );
$emailStatus = get_transient( 'employees-quick--email-status' );
$emailMessage = get_transient( 'employees-quick--email-message' );
?>
<div class="c-form--row">
<label class="c-form--label" for="form-email">Email address*</label>
<div class="c-form--input-wrap">
<input type="email" class="c-form--input <?php if ($response) { echo 'c-form--input--error'; } ?>" id="form-email" name="email" value="">
<input type="email" class="c-form--input <?php if ($emailStatus) { echo "c-form--input--$emailStatus"; } ?>" id="form-email" name="email" value="<?php echo $emailValue; ?>">
</div>
<?php if ($response): ?>
<div class="c-form--validation-error">
Email address is required
<?php if ($emailMessage): ?>
<div class="c-form--validation-<?php echo $emailStatus; ?>">
<?php echo $emailMessage; ?>
</div>
<?php endif; ?>
</div><!-- .c-form--row -->
......@@ -66,19 +79,24 @@ $_nonce = wp_create_nonce( 'my_post_form_nonce' );
</div>
</div><!-- .c-form--row -->
<?php
$agreeValue = get_transient( 'employees-quick--agree-value' );
$agreeStatus = get_transient( 'employees-quick--agree-status' );
$agreeMessage = get_transient( 'employees-quick--agree-message' );
?>
<div class="c-form--row">
<div class="c-form--checkbox-wrap">
<input id="form-agree" type="checkbox" class="c-form--checkbox <?php if ($response) { echo 'c-form--checkbox--error'; } ?>" name="agree" value="1">
<input id="form-agree" type="checkbox" class="c-form--checkbox <?php if ($agreeStatus) { echo "c-form--checkbox--$agreeStatus"; } ?>" name="agree" value="1" <?php if ($agreeValue): ?> checked="checked"<?php endif; ?>>
<label class="c-form--label-checkbox" for="form-agree">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem possimus, delectus unde enim dolores doloribus, recusandae a veritatis ducimus repudiandae iste eos voluptatum architecto mollitia?</label>
</div>
<?php if ($response): ?>
<div class="c-form--validation-error">
You have to agree with conditions
<?php if ($agreeMessage): ?>
<div class="c-form--validation-<?php echo $agreeStatus; ?>">
<?php echo $agreeMessage; ?>
</div>
<?php endif; ?>
</div><!-- .c-form--row -->
<input type="hidden" name="action" value="employees_quick_post">
<!-- <input type="hidden" name="_nonce" value="<?php echo $_nonce; ?>" /> -->
<?php wp_nonce_field('employees_quick_post_nonce'); ?>
</form>
......@@ -5,5 +5,9 @@
/* critical:end */
.c-form--input--error { border: 1px solid #f90000; }
.c-form--input--success { border: 1px solid green; }
.c-form--input--warning { border: 1px solid orange; }
.c-form--validation-error { color: #f90000; margin-bottom: 10px;}
.c-form--validation-success { color: green; margin-bottom: 10px;}
.c-form--validation-warning { color: orange; margin-bottom: 10px;}
This diff is collapsed.
This diff is collapsed.
......@@ -33,14 +33,14 @@ define('cityID', $cityID);
<style><?php include 'css/core-a25434ed1d.min.css'; ?></style>
<link rel="preload" href="/wp-content/themes/biuro/css/main-e48562fc43.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main-4233b63eb8.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/fonts/pt_sans_narrow.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/wp-content/themes/biuro/fonts/pt_sans_narrow_bold.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/wp-content/themes/biuro/fonts/bebas-neue.woff2" as="font" type="font/woff2" crossorigin>
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-e48562fc43.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-4233b63eb8.min.css">
</noscript>
<?php wp_head(); ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment