Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191
This commit is contained in:
528
chat/templates/Form Builder/public/css/public-style.css
Normal file
528
chat/templates/Form Builder/public/css/public-style.css
Normal file
@@ -0,0 +1,528 @@
|
||||
/**
|
||||
* PC Form Builder Public Styles
|
||||
*
|
||||
* Frontend styling for the form builder plugin.
|
||||
*
|
||||
* @package PCFormBuilder
|
||||
*/
|
||||
|
||||
/* CSS Variables */
|
||||
:root {
|
||||
--pcfb-primary: #2271b1;
|
||||
--pcfb-primary-dark: #135e96;
|
||||
--pcfb-primary-light: #72aee6;
|
||||
--pcfb-success: #00a32a;
|
||||
--pcfb-success-light: #dcfce1;
|
||||
--pcfb-danger: #d63638;
|
||||
--pcfb-danger-light: #fbe9e9;
|
||||
--pcfb-warning: #dba617;
|
||||
--pcfb-warning-light: #fff9c4;
|
||||
--pcfb-text: #3c434a;
|
||||
--pcfb-text-light: #6c7781;
|
||||
--pcfb-bg: #ffffff;
|
||||
--pcfb-bg-light: #f6f7f7;
|
||||
--pcfb-border: #e1e2e3;
|
||||
--pcfb-border-radius: 6px;
|
||||
--pcfb-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
--pcfb-transition: all 0.2s ease;
|
||||
--pcfb-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
}
|
||||
|
||||
/* Reset & Base */
|
||||
.pcfb-form-wrapper {
|
||||
font-family: var(--pcfb-font-family);
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
color: var(--pcfb-text);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.pcfb-form-wrapper *,
|
||||
.pcfb-form-wrapper *::before,
|
||||
.pcfb-form-wrapper *::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Container */
|
||||
.pcfb-form-container {
|
||||
background: var(--pcfb-bg);
|
||||
border: 1px solid var(--pcfb-border);
|
||||
border-radius: var(--pcfb-border-radius);
|
||||
box-shadow: var(--pcfb-box-shadow);
|
||||
padding: 30px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Form Header */
|
||||
.pcfb-form-header {
|
||||
margin-bottom: 25px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid var(--pcfb-border);
|
||||
}
|
||||
|
||||
.pcfb-form-title {
|
||||
margin: 0 0 10px;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--pcfb-text);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.pcfb-form-description {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: var(--pcfb-text-light);
|
||||
}
|
||||
|
||||
/* Form Fields */
|
||||
.pcfb-form-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.pcfb-form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pcfb-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: var(--pcfb-text);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.pcfb-required {
|
||||
color: var(--pcfb-danger);
|
||||
margin-left: 3px;
|
||||
}
|
||||
|
||||
/* Input Styles */
|
||||
.pcfb-input,
|
||||
.pcfb-textarea,
|
||||
.pcfb-select {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
font-family: inherit;
|
||||
font-size: 15px;
|
||||
line-height: 1.5;
|
||||
color: var(--pcfb-text);
|
||||
background-color: var(--pcfb-bg);
|
||||
border: 1px solid var(--pcfb-border);
|
||||
border-radius: var(--pcfb-border-radius);
|
||||
transition: var(--pcfb-transition);
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
.pcfb-input:focus,
|
||||
.pcfb-textarea:focus,
|
||||
.pcfb-select:focus {
|
||||
outline: none;
|
||||
border-color: var(--pcfb-primary);
|
||||
box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.15);
|
||||
}
|
||||
|
||||
.pcfb-input::placeholder,
|
||||
.pcfb-textarea::placeholder {
|
||||
color: var(--pcfb-text-light);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.pcfb-textarea {
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
max-height: 400px;
|
||||
}
|
||||
|
||||
.pcfb-select {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c7781' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 15px center;
|
||||
padding-right: 40px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Checkbox Styles */
|
||||
.pcfb-checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.pcfb-checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: 400;
|
||||
font-size: 15px;
|
||||
color: var(--pcfb-text);
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
.pcfb-checkbox-label:hover .pcfb-checkbox-text {
|
||||
color: var(--pcfb-primary);
|
||||
}
|
||||
|
||||
.pcfb-checkbox {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
accent-color: var(--pcfb-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pcfb-checkbox:checked + .pcfb-checkbox-text {
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-checkbox-text {
|
||||
transition: var(--pcfb-transition);
|
||||
}
|
||||
|
||||
/* Form Footer */
|
||||
.pcfb-form-footer {
|
||||
margin-top: 30px;
|
||||
padding-top: 25px;
|
||||
border-top: 1px solid var(--pcfb-border);
|
||||
}
|
||||
|
||||
/* Submit Button */
|
||||
.pcfb-submit-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 14px 30px;
|
||||
font-family: inherit;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
color: #fff;
|
||||
background: var(--pcfb-primary);
|
||||
border: none;
|
||||
border-radius: var(--pcfb-border-radius);
|
||||
cursor: pointer;
|
||||
transition: var(--pcfb-transition);
|
||||
text-decoration: none;
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
.pcfb-submit-button:hover {
|
||||
background: var(--pcfb-primary-dark);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.pcfb-submit-button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.pcfb-submit-button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* Spinner */
|
||||
.pcfb-spinner {
|
||||
display: inline-block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: pcfb-spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes pcfb-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Error Messages */
|
||||
.pcfb-field-error {
|
||||
display: none;
|
||||
margin-top: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--pcfb-danger);
|
||||
}
|
||||
|
||||
.pcfb-form-group.error .pcfb-input,
|
||||
.pcfb-form-group.error .pcfb-textarea,
|
||||
.pcfb-form-group.error .pcfb-select {
|
||||
border-color: var(--pcfb-danger);
|
||||
background-color: var(--pcfb-danger-light);
|
||||
}
|
||||
|
||||
.pcfb-form-group.error .pcfb-field-error {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Success/Error Messages */
|
||||
.pcfb-form-message {
|
||||
margin-top: 20px;
|
||||
padding: 15px 20px;
|
||||
border-radius: var(--pcfb-border-radius);
|
||||
animation: pcfb-fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes pcfb-fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.pcfb-success-message {
|
||||
background-color: var(--pcfb-success-light);
|
||||
border: 1px solid var(--pcfb-success);
|
||||
}
|
||||
|
||||
.pcfb-error-message {
|
||||
background-color: var(--pcfb-danger-light);
|
||||
border: 1px solid var(--pcfb-danger);
|
||||
}
|
||||
|
||||
.pcfb-message-content {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.pcfb-message-icon {
|
||||
font-size: 24px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pcfb-success-message .pcfb-message-icon {
|
||||
color: var(--pcfb-success);
|
||||
}
|
||||
|
||||
.pcfb-error-message .pcfb-message-icon {
|
||||
color: var(--pcfb-danger);
|
||||
}
|
||||
|
||||
.pcfb-message-text {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
/* No Fields Message */
|
||||
.pcfb-no-fields {
|
||||
text-align: center;
|
||||
color: var(--pcfb-text-light);
|
||||
padding: 40px 20px;
|
||||
background: var(--pcfb-bg-light);
|
||||
border-radius: var(--pcfb-border-radius);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media screen and (max-width: 600px) {
|
||||
.pcfb-form-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.pcfb-form-title {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.pcfb-form-fields {
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.pcfb-input,
|
||||
.pcfb-textarea,
|
||||
.pcfb-select {
|
||||
padding: 10px 12px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.pcfb-submit-button {
|
||||
width: 100%;
|
||||
padding: 14px 20px;
|
||||
}
|
||||
|
||||
.pcfb-checkbox-label {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dark Mode Support */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.pcfb-form-wrapper {
|
||||
--pcfb-text: #f0f0f1;
|
||||
--pcfb-text-light: #a0a5aa;
|
||||
--pcfb-bg: #1d2327;
|
||||
--pcfb-bg-light: #2c3338;
|
||||
--pcfb-border: #3c434a;
|
||||
--pcfb-border-radius: 6px;
|
||||
--pcfb-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.pcfb-form-container {
|
||||
background: var(--pcfb-bg);
|
||||
border-color: var(--pcfb-border);
|
||||
}
|
||||
|
||||
.pcfb-form-header {
|
||||
border-bottom-color: var(--pcfb-border);
|
||||
}
|
||||
|
||||
.pcfb-form-title {
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-form-description {
|
||||
color: var(--pcfb-text-light);
|
||||
}
|
||||
|
||||
.pcfb-label {
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-input,
|
||||
.pcfb-textarea,
|
||||
.pcfb-select {
|
||||
background-color: var(--pcfb-bg-light);
|
||||
border-color: var(--pcfb-border);
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-input::placeholder,
|
||||
.pcfb-textarea::placeholder {
|
||||
color: var(--pcfb-text-light);
|
||||
}
|
||||
|
||||
.pcfb-checkbox-label {
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-form-footer {
|
||||
border-top-color: var(--pcfb-border);
|
||||
}
|
||||
|
||||
.pcfb-message-text {
|
||||
color: var(--pcfb-text);
|
||||
}
|
||||
|
||||
.pcfb-no-fields {
|
||||
background: var(--pcfb-bg-light);
|
||||
color: var(--pcfb-text-light);
|
||||
}
|
||||
}
|
||||
|
||||
/* High Contrast Mode */
|
||||
@media (prefers-contrast: high) {
|
||||
.pcfb-form-container {
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.pcfb-input,
|
||||
.pcfb-textarea,
|
||||
.pcfb-select {
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.pcfb-submit-button {
|
||||
border: 2px solid #fff;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reduced Motion */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.pcfb-form-wrapper *,
|
||||
.pcfb-form-wrapper *::before,
|
||||
.pcfb-form-wrapper *::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print Styles */
|
||||
@media print {
|
||||
.pcfb-form-wrapper {
|
||||
box-shadow: none;
|
||||
border: 1px solid #000;
|
||||
}
|
||||
|
||||
.pcfb-form-container {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.pcfb-submit-button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Accessibility Focus Styles */
|
||||
.pcfb-input:focus-visible,
|
||||
.pcfb-textarea:focus-visible,
|
||||
.pcfb-select:focus-visible,
|
||||
.pcfb-checkbox:focus-visible {
|
||||
outline: 2px solid var(--pcfb-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* Validation Styles */
|
||||
.pcfb-input:invalid:not(:placeholder-shown),
|
||||
.pcfb-input.pattern-violation:not(:placeholder-shown) {
|
||||
border-color: var(--pcfb-danger);
|
||||
}
|
||||
|
||||
/* Loading State */
|
||||
.pcfb-form.loading .pcfb-submit-text {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.pcfb-form.loading .pcfb-submit-loader {
|
||||
display: inline-flex !important;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.pcfb-form.loading .pcfb-submit-button {
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
/* Form Layout Variations */
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-form-group {
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-label {
|
||||
flex: 0 0 150px;
|
||||
padding-top: 12px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-input,
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-textarea,
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-select {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-form-group {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.pcfb-form-wrapper.pcfb-form-aligned .pcfb-label {
|
||||
flex: none;
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
136
chat/templates/Form Builder/public/js/public-script.js
Normal file
136
chat/templates/Form Builder/public/js/public-script.js
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* PC Form Builder Public Scripts
|
||||
*
|
||||
* Frontend JavaScript functionality for form handling.
|
||||
*
|
||||
* @package PCFormBuilder
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
var PCFB_Public = {
|
||||
init: function() {
|
||||
this.initForms();
|
||||
},
|
||||
|
||||
initForms: function() {
|
||||
var self = this;
|
||||
|
||||
$(document).on('submit', '.pcfb-form', function(e) {
|
||||
e.preventDefault();
|
||||
self.handleFormSubmit($(this));
|
||||
});
|
||||
},
|
||||
|
||||
handleFormSubmit: function($form) {
|
||||
var self = this;
|
||||
var formId = $form.data('form-id');
|
||||
var $submitButton = $form.find('.pcfb-submit-button');
|
||||
var $submitText = $form.find('.pcfb-submit-text');
|
||||
var $submitLoader = $form.find('.pcfb-submit-loader');
|
||||
var $successMessage = $form.closest('.pcfb-form-container').find('.pcfb-success-message');
|
||||
var $errorMessage = $form.closest('.pcfb-form-container').find('.pcfb-error-message');
|
||||
|
||||
$form.find('.pcfb-form-group').removeClass('error');
|
||||
$form.find('.pcfb-field-error').text('');
|
||||
$errorMessage.hide().find('.pcfb-message-text').text('');
|
||||
$successMessage.hide();
|
||||
|
||||
var formData = $form.serialize();
|
||||
var ajaxData = {
|
||||
action: 'pcfb_submit_form',
|
||||
form_id: formId,
|
||||
form_data: {},
|
||||
nonce: pcfbVars.nonce
|
||||
};
|
||||
|
||||
$form.find('input, textarea, select').each(function() {
|
||||
var $field = $(this);
|
||||
var name = $field.attr('name');
|
||||
if (name && name !== 'action' && name !== 'form_id' && name !== 'pcfb_nonce') {
|
||||
if ($field.is(':checkbox')) {
|
||||
if ($field.is(':checked')) {
|
||||
if (!ajaxData.form_data[name]) {
|
||||
ajaxData.form_data[name] = [];
|
||||
}
|
||||
ajaxData.form_data[name].push($field.val());
|
||||
}
|
||||
} else if ($field.is(':radio')) {
|
||||
if ($field.is(':checked')) {
|
||||
ajaxData.form_data[name] = $field.val();
|
||||
}
|
||||
} else {
|
||||
ajaxData.form_data[name] = $field.val();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$form.addClass('loading');
|
||||
$submitButton.prop('disabled', true);
|
||||
$submitText.hide();
|
||||
$submitLoader.show();
|
||||
|
||||
$.ajax({
|
||||
url: pcfbVars.ajaxurl,
|
||||
type: 'POST',
|
||||
data: ajaxData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
$form.removeClass('loading');
|
||||
$submitButton.prop('disabled', false);
|
||||
$submitText.show();
|
||||
$submitLoader.hide();
|
||||
|
||||
if (response.success) {
|
||||
$successMessage.find('.pcfb-message-text').text(response.data.message || 'Thank you!');
|
||||
$successMessage.show();
|
||||
$form.hide();
|
||||
|
||||
if (response.data.response_id) {
|
||||
console.log('Response ID:', response.data.response_id);
|
||||
}
|
||||
} else {
|
||||
if (response.data.errors) {
|
||||
$.each(response.data.errors, function(fieldName, errorMessage) {
|
||||
var $fieldGroup = $form.find('[name="' + fieldName + '"]').closest('.pcfb-form-group');
|
||||
if ($fieldGroup.length === 0) {
|
||||
$fieldGroup = $form.find('[name^="' + fieldName + '"]').closest('.pcfb-form-group');
|
||||
}
|
||||
if ($fieldGroup.length > 0) {
|
||||
$fieldGroup.addClass('error');
|
||||
$fieldGroup.find('.pcfb-field-error').text(errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var errorText = response.data.message || 'An error occurred. Please try again.';
|
||||
$errorMessage.find('.pcfb-message-text').text(errorText);
|
||||
$errorMessage.show();
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$form.removeClass('loading');
|
||||
$submitButton.prop('disabled', false);
|
||||
$submitText.show();
|
||||
$submitLoader.hide();
|
||||
|
||||
var errorText = 'An error occurred. Please try again.';
|
||||
if (xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message) {
|
||||
errorText = xhr.responseJSON.data.message;
|
||||
} else if (xhr.statusText) {
|
||||
errorText = xhr.statusText;
|
||||
}
|
||||
|
||||
$errorMessage.find('.pcfb-message-text').text(errorText);
|
||||
$errorMessage.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
PCFB_Public.init();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
166
chat/templates/Form Builder/public/templates/form-display.php
Normal file
166
chat/templates/Form Builder/public/templates/form-display.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Form Display Template
|
||||
*
|
||||
* Frontend template for displaying forms.
|
||||
*
|
||||
* @package PCFormBuilder
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$form_id = ! empty( $form->id ) ? $form->id : 0;
|
||||
$form_name = ! empty( $form->name ) ? $form->name : '';
|
||||
$form_description = ! empty( $form->description ) ? $form->description : '';
|
||||
$submit_text = ! empty( $settings['submit_text'] ) ? $settings['submit_text'] : __( 'Submit', 'pc-form-builder-xyz123' );
|
||||
$success_message = ! empty( $settings['success_message'] ) ? $settings['success_message'] : __( 'Thank you! Your response has been submitted.', 'pc-form-builder-xyz123' );
|
||||
?>
|
||||
|
||||
<div class="pcfb-form-wrapper" id="pcfb-form-wrapper-<?php echo esc_attr( $form_id ); ?>">
|
||||
<div class="pcfb-form-container">
|
||||
<?php if ( ! empty( $form_name ) ) : ?>
|
||||
<div class="pcfb-form-header">
|
||||
<h2 class="pcfb-form-title"><?php echo esc_html( $form_name ); ?></h2>
|
||||
<?php if ( ! empty( $form_description ) ) : ?>
|
||||
<p class="pcfb-form-description"><?php echo esc_html( $form_description ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="pcfb-form" id="pcfb-form-<?php echo esc_attr( $form_id ); ?>" data-form-id="<?php echo esc_attr( $form_id ); ?>">
|
||||
<?php wp_nonce_field( 'pcfb_public_nonce', 'pcfb_nonce' ); ?>
|
||||
<input type="hidden" name="action" value="pcfb_submit_form">
|
||||
<input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>">
|
||||
|
||||
<div class="pcfb-form-fields">
|
||||
<?php if ( ! empty( $fields ) && is_array( $fields ) ) : ?>
|
||||
<?php foreach ( $fields as $field ) : ?>
|
||||
<?php
|
||||
$field_id = ! empty( $field->id ) ? $field->id : 0;
|
||||
$field_name = ! empty( $field->field_name ) ? $field->field_name : '';
|
||||
$field_label = ! empty( $field->field_label ) ? $field->field_label : '';
|
||||
$field_type = ! empty( $field->field_type ) ? $field->field_type : 'text';
|
||||
$placeholder = ! empty( $field->placeholder ) ? $field->placeholder : '';
|
||||
$options = ! empty( $field->options ) ? maybe_unserialize( $field->options ) : array();
|
||||
$validation_rules = ! empty( $field->validation_rules ) ? maybe_unserialize( $field->validation_rules ) : array();
|
||||
$is_required = ! empty( $validation_rules['required'] );
|
||||
?>
|
||||
|
||||
<div class="pcfb-form-group pcfb-field-<?php echo esc_attr( $field_type ); ?>">
|
||||
<label class="pcfb-label" for="<?php echo esc_attr( 'pcfb-' . $form_id . '-' . $field_name ); ?>">
|
||||
<?php echo esc_html( $field_label ); ?>
|
||||
<?php if ( $is_required ) : ?>
|
||||
<span class="pcfb-required">*</span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
|
||||
<?php switch ( $field_type ) :
|
||||
case 'text':
|
||||
case 'email':
|
||||
case 'name':
|
||||
?>
|
||||
<input
|
||||
type="<?php echo esc_attr( 'email' === $field_type ? 'email' : 'text' ); ?>"
|
||||
id="<?php echo esc_attr( 'pcfb-' . $form_id . '-' . $field_name ); ?>"
|
||||
name="<?php echo esc_attr( $field_name ); ?>"
|
||||
class="pcfb-input"
|
||||
placeholder="<?php echo esc_attr( $placeholder ); ?>"
|
||||
<?php if ( $is_required ) : ?>required<?php endif; ?>
|
||||
>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'response':
|
||||
?>
|
||||
<textarea
|
||||
id="<?php echo esc_attr( 'pcfb-' . $form_id . '-' . $field_name ); ?>"
|
||||
name="<?php echo esc_attr( $field_name ); ?>"
|
||||
class="pcfb-textarea"
|
||||
rows="5"
|
||||
placeholder="<?php echo esc_attr( $placeholder ); ?>"
|
||||
<?php if ( $is_required ) : ?>required<?php endif; ?>
|
||||
></textarea>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'dropdown':
|
||||
?>
|
||||
<select
|
||||
id="<?php echo esc_attr( 'pcfb-' . $form_id . '-' . $field_name ); ?>"
|
||||
name="<?php echo esc_attr( $field_name ); ?>"
|
||||
class="pcfb-select"
|
||||
<?php if ( $is_required ) : ?>required<?php endif; ?>
|
||||
>
|
||||
<option value=""><?php echo esc_html( $placeholder ? $placeholder : __( '-- Select --', 'pc-form-builder-xyz123' ) ); ?></option>
|
||||
<?php if ( ! empty( $options ) && is_array( $options ) ) : ?>
|
||||
<?php foreach ( $options as $option ) : ?>
|
||||
<?php if ( ! empty( trim( $option ) ) ) : ?>
|
||||
<option value="<?php echo esc_attr( trim( $option ) ); ?>"><?php echo esc_html( trim( $option ) ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
if ( ! empty( $options ) && is_array( $options ) ) :
|
||||
?>
|
||||
<div class="pcfb-checkbox-group">
|
||||
<?php foreach ( $options as $index => $option ) : ?>
|
||||
<?php if ( ! empty( trim( $option ) ) ) : ?>
|
||||
<?php $checkbox_id = 'pcfb-' . $form_id . '-' . $field_name . '-' . $index; ?>
|
||||
<label class="pcfb-checkbox-label" for="<?php echo esc_attr( $checkbox_id ); ?>">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="<?php echo esc_attr( $checkbox_id ); ?>"
|
||||
name="<?php echo esc_attr( $field_name ); ?>[]"
|
||||
value="<?php echo esc_attr( trim( $option ) ); ?>"
|
||||
class="pcfb-checkbox"
|
||||
>
|
||||
<span class="pcfb-checkbox-text"><?php echo esc_html( trim( $option ) ); ?></span>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
break;
|
||||
endswitch; ?>
|
||||
|
||||
<span class="pcfb-field-error" id="<?php echo esc_attr( 'pcfb-error-' . $form_id . '-' . $field_name ); ?>"></span>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else : ?>
|
||||
<p class="pcfb-no-fields"><?php esc_html_e( 'This form has no fields yet.', 'pc-form-builder-xyz123' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="pcfb-form-footer">
|
||||
<button type="submit" class="pcfb-submit-button">
|
||||
<span class="pcfb-submit-text"><?php echo esc_html( $submit_text ); ?></span>
|
||||
<span class="pcfb-submit-loader" style="display: none;">
|
||||
<span class="pcfb-spinner"></span>
|
||||
<?php esc_html_e( 'Submitting...', 'pc-form-builder-xyz123' ); ?>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="pcfb-form-message pcfb-success-message" style="display: none;">
|
||||
<div class="pcfb-message-content">
|
||||
<span class="pcfb-message-icon dashicons dashicons-yes-alt"></span>
|
||||
<p class="pcfb-message-text"><?php echo esc_html( $success_message ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pcfb-form-message pcfb-error-message" style="display: none;">
|
||||
<div class="pcfb-message-content">
|
||||
<span class="pcfb-message-icon dashicons dashicons-warning"></span>
|
||||
<p class="pcfb-message-text"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user