Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191

This commit is contained in:
southseact-3d
2026-02-07 20:32:41 +00:00
commit ed67b7741b
252 changed files with 99814 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
<?php
/**
* Admin Menu Class
*
* Handles admin menu registration and page routing.
*
* @package PCFormBuilder
*/
class PCFB_Admin_Menu {
private static $instance = null;
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'handle_form_actions' ) );
add_action( 'wp_ajax_pcfb_add_field', array( $this, 'ajax_add_field' ) );
}
public function add_admin_menu() {
add_menu_page(
__( 'Form Builder', 'pc-form-builder-xyz123' ),
__( 'Form Builder', 'pc-form-builder-xyz123' ),
'manage_options',
'pcfb-form-builder',
array( $this, 'render_form_builder_page' ),
'dashicons-feedback',
30
);
add_submenu_page(
'pcfb-form-builder',
__( 'Form Builder', 'pc-form-builder-xyz123' ),
__( 'Form Builder', 'pc-form-builder-xyz123' ),
'manage_options',
'pcfb-form-builder',
array( $this, 'render_form_builder_page' )
);
add_submenu_page(
'pcfb-form-builder',
__( 'All Forms', 'pc-form-builder-xyz123' ),
__( 'All Forms', 'pc-form-builder-xyz123' ),
'manage_options',
'pcfb-all-forms',
array( $this, 'render_all_forms_page' )
);
add_submenu_page(
'pcfb-form-builder',
__( 'Responses', 'pc-form-builder-xyz123' ),
__( 'Responses', 'pc-form-builder-xyz123' ),
'manage_options',
'pcfb-responses',
array( $this, 'render_responses_page' )
);
}
public function render_form_builder_page() {
require_once PCFB_PLUGIN_DIR . 'admin/class-admin-helper.php';
$helper = PCFB_Admin_Helper::get_instance();
$form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
if ( $form_id > 0 ) {
include PCFB_PLUGIN_DIR . 'admin/page-form-builder.php';
} else {
include PCFB_PLUGIN_DIR . 'admin/page-form-builder.php';
}
}
public function render_all_forms_page() {
include PCFB_PLUGIN_DIR . 'admin/page-all-forms.php';
}
public function render_responses_page() {
$form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
$response_id = isset( $_GET['response_id'] ) ? intval( $_GET['response_id'] ) : 0;
if ( $response_id > 0 ) {
include PCFB_PLUGIN_DIR . 'admin/page-response-detail.php';
} elseif ( $form_id > 0 ) {
include PCFB_PLUGIN_DIR . 'admin/page-form-responses.php';
} else {
include PCFB_PLUGIN_DIR . 'admin/page-responses.php';
}
}
public function handle_form_actions() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( ! isset( $_POST['pcfb_action'] ) ) {
return;
}
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'pcfb_admin_action' ) ) {
return;
}
$action = sanitize_text_field( $_POST['pcfb_action'] );
switch ( $action ) {
case 'save_form':
$this->handle_save_form();
break;
case 'delete_form':
$this->handle_delete_form();
break;
case 'toggle_status':
$this->handle_toggle_status();
break;
}
}
private function handle_save_form() {
$form_data = isset( $_POST['form'] ) ? $_POST['form'] : array();
$fields = isset( $_POST['fields'] ) ? $_POST['fields'] : array();
$handler = PC_Form_Handler::get_instance();
$form_id = $handler->save_form( $form_data, $fields );
if ( $form_id ) {
$edit_url = admin_url( 'admin.php?page=pcfb-form-builder&form_id=' . $form_id );
$shortcode = '[pcfb-form id="' . $form_id . '"]';
add_action( 'admin_notices', function() use ( $edit_url, $shortcode ) {
echo '<div class="notice notice-success is-dismissible"><p>';
echo sprintf( __( 'Form saved successfully!', 'pc-form-builder-xyz123' ) );
echo '</p><p><strong>' . esc_html__( 'Shortcode:', 'pc-form-builder-xyz123' ) . '</strong> <code onclick="this.select(); document.execCommand(\'copy\');" style="background: #f0f0f1; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 14px;">' . esc_html( $shortcode ) . '</code></p>';
echo '<p><a href="' . esc_url( $edit_url ) . '" class="button button-primary" style="margin-top: 10px;">' . esc_html__( 'Go to Form Builder', 'pc-form-builder-xyz123' ) . '</a></p></div>';
} );
wp_redirect( admin_url( 'admin.php?page=pcfb-form-builder&form_id=' . $form_id ) );
exit;
} else {
add_action( 'admin_notices', function() {
echo '<div class="notice notice-error is-dismissible"><p>';
echo esc_html__( 'Failed to save form. Please try again.', 'pc-form-builder-xyz123' );
echo '</p></div>';
} );
}
}
private function handle_delete_form() {
$form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
if ( $form_id > 0 && PC_Form_Handler::delete_form( $form_id ) ) {
add_action( 'admin_notices', function() {
echo '<div class="notice notice-success is-dismissible"><p>';
echo esc_html__( 'Form deleted successfully.', 'pc-form-builder-xyz123' );
echo '</p></div>';
} );
} else {
add_action( 'admin_notices', function() {
echo '<div class="notice notice-error is-dismissible"><p>';
echo esc_html__( 'Failed to delete form. Please try again.', 'pc-form-builder-xyz123' );
echo '</p></div>';
} );
}
}
private function handle_toggle_status() {
global $wpdb;
$form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
if ( $form_id > 0 ) {
$form = PC_Form_Handler::get_form_by_id( $form_id );
if ( $form ) {
$new_status = 'active' === $form->status ? 'inactive' : 'active';
$table_name = $wpdb->prefix . 'pcfb_forms';
$wpdb->update( $table_name, array( 'status' => $new_status ), array( 'id' => $form_id ) );
}
}
}
public function ajax_add_field() {
check_ajax_referer( 'pcfb_admin_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => __( 'Permission denied.', 'pc-form-builder-xyz123' ) ) );
}
$field_type = isset( $_POST['field_type'] ) ? sanitize_text_field( $_POST['field_type'] ) : 'text';
$field_index = isset( $_POST['field_index'] ) ? intval( $_POST['field_index'] ) : 0;
require_once PCFB_PLUGIN_DIR . 'admin/class-admin-helper.php';
$helper = PCFB_Admin_Helper::get_instance();
ob_start();
$helper->render_new_field_item( $field_type, $field_index );
$html = ob_get_clean();
wp_send_json_success( array( 'html' => $html ) );
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* Admin Helper Class
*
* Provides helper methods for admin pages.
*
* @package PCFormBuilder
*/
class PCFB_Admin_Helper {
private static $instance = null;
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function get_field_types() {
return array(
'text' => __( 'Text Input', 'pc-form-builder-xyz123' ),
'email' => __( 'Email', 'pc-form-builder-xyz123' ),
'name' => __( 'Name', 'pc-form-builder-xyz123' ),
'response' => __( 'Response', 'pc-form-builder-xyz123' ),
'dropdown' => __( 'Dropdown', 'pc-form-builder-xyz123' ),
'checkbox' => __( 'Checkbox', 'pc-form-builder-xyz123' ),
);
}
public function get_form_fields( $form_id ) {
global $wpdb;
$table_name = $wpdb->prefix . 'pcfb_fields';
return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE form_id = %d ORDER BY sort_order ASC", $form_id ) );
}
public function render_field_item( $field, $index = 0 ) {
$validation_rules = maybe_unserialize( $field->validation_rules );
$options = maybe_unserialize( $field->options );
$field_types = $this->get_field_types();
$field_type_label = isset( $field_types[ $field->field_type ] ) ? $field_types[ $field->field_type ] : $field->field_type;
?>
<div class="pcfb-field-item" data-field-id="<?php echo esc_attr( $field->id ); ?>" data-field-type="<?php echo esc_attr( $field->field_type ); ?>">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][id]" value="<?php echo esc_attr( $field->id ); ?>">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][field_type]" value="<?php echo esc_attr( $field->field_type ); ?>">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][field_name]" value="<?php echo esc_attr( $field->field_name ); ?>">
<div class="pcfb-field-header">
<span class="pcfb-field-type-badge"><?php echo esc_html( $field_type_label ); ?></span>
<span class="pcfb-field-name-display"><?php echo esc_html( $field->field_name ); ?></span>
<div class="pcfb-field-actions">
<button type="button" class="button button-small pcfb-toggle-field">
<span class="dashicons dashicons-arrow-up-alt2"></span>
</button>
</div>
</div>
<div class="pcfb-field-content">
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Field Label', 'pc-form-builder-xyz123' ); ?></label>
<input type="text" name="fields[<?php echo esc_attr( $index ); ?>][field_label]" value="<?php echo esc_attr( $field->field_label ); ?>" class="pcfb-field-label-input" placeholder="<?php esc_attr_e( 'Enter field label', 'pc-form-builder-xyz123' ); ?>">
</div>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Placeholder Text', 'pc-form-builder-xyz123' ); ?></label>
<input type="text" name="fields[<?php echo esc_attr( $index ); ?>][placeholder]" value="<?php echo esc_attr( $field->placeholder ); ?>" placeholder="<?php esc_attr_e( 'Optional placeholder text', 'pc-form-builder-xyz123' ); ?>">
</div>
<?php if ( 'dropdown' === $field->field_type ) : ?>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Options', 'pc-form-builder-xyz123' ); ?></label>
<textarea name="fields[<?php echo esc_attr( $index ); ?>][options]" rows="3" placeholder="<?php esc_attr_e( 'One option per line', 'pc-form-builder-xyz123' ); ?>"><?php echo ! empty( $options ) ? esc_textarea( implode( "\n", $options ) ) : ''; ?></textarea>
<p class="description"><?php esc_html_e( 'Enter each option on a new line.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php elseif ( 'checkbox' === $field->field_type ) : ?>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Checkbox Options', 'pc-form-builder-xyz123' ); ?></label>
<textarea name="fields[<?php echo esc_attr( $index ); ?>][options]" rows="3" placeholder="<?php esc_attr_e( 'One option per line', 'pc-form-builder-xyz123' ); ?>"><?php echo ! empty( $options ) ? esc_textarea( implode( "\n", $options ) ) : ''; ?></textarea>
<p class="description"><?php esc_html_e( 'Enter each checkbox option on a new line.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php endif; ?>
<div class="pcfb-form-group pcfb-validation-group">
<label class="pcfb-checkbox-label">
<input type="checkbox" name="fields[<?php echo esc_attr( $index ); ?>][validation_rules][required]" value="1" <?php checked( ! empty( $validation_rules['required'] ), true ); ?>>
<?php esc_html_e( 'Required field', 'pc-form-builder-xyz123' ); ?>
</label>
</div>
</div>
<div class="pcfb-field-footer">
<button type="button" class="button button-link-delete pcfb-delete-field"><?php esc_html_e( 'Remove Field', 'pc-form-builder-xyz123' ); ?></button>
</div>
</div>
<?php
}
public function render_new_field_item( $field_type, $index ) {
$field_types = $this->get_field_types();
$field_type_label = isset( $field_types[ $field_type ] ) ? $field_types[ $field_type ] : $field_type;
$default_labels = array(
'text' => __( 'Text Field', 'pc-form-builder-xyz123' ),
'email' => __( 'Email Address', 'pc-form-builder-xyz123' ),
'name' => __( 'Full Name', 'pc-form-builder-xyz123' ),
'response' => __( 'Your Response', 'pc-form-builder-xyz123' ),
'dropdown' => __( 'Select Option', 'pc-form-builder-xyz123' ),
'checkbox' => __( 'Checkboxes', 'pc-form-builder-xyz123' ),
);
$default_label = isset( $default_labels[ $field_type ] ) ? $default_labels[ $field_type ] : __( 'Field', 'pc-form-builder-xyz123' );
$placeholder = '';
if ( 'response' === $field_type ) {
$placeholder = __( 'Enter your response here...', 'pc-form-builder-xyz123' );
}
?>
<div class="pcfb-field-item pcfb-new-field" data-field-id="new" data-field-type="<?php echo esc_attr( $field_type ); ?>">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][id]" value="">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][field_type]" value="<?php echo esc_attr( $field_type ); ?>">
<input type="hidden" name="fields[<?php echo esc_attr( $index ); ?>][field_name]" value="">
<div class="pcfb-field-header">
<span class="pcfb-field-type-badge"><?php echo esc_html( $field_type_label ); ?></span>
<span class="pcfb-field-name-display"><?php echo esc_html( sanitize_title( $default_label ) ); ?></span>
<div class="pcfb-field-actions">
<button type="button" class="button button-small pcfb-toggle-field">
<span class="dashicons dashicons-arrow-up-alt2"></span>
</button>
</div>
</div>
<div class="pcfb-field-content">
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Field Label', 'pc-form-builder-xyz123' ); ?></label>
<input type="text" name="fields[<?php echo esc_attr( $index ); ?>][field_label]" value="<?php echo esc_attr( $default_label ); ?>" class="pcfb-field-label-input" placeholder="<?php esc_attr_e( 'Enter field label', 'pc-form-builder-xyz123' ); ?>">
</div>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Placeholder Text', 'pc-form-builder-xyz123' ); ?></label>
<input type="text" name="fields[<?php echo esc_attr( $index ); ?>][placeholder]" value="<?php echo esc_attr( $placeholder ); ?>" placeholder="<?php esc_attr_e( 'Optional placeholder text', 'pc-form-builder-xyz123' ); ?>">
</div>
<?php if ( 'dropdown' === $field_type ) : ?>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Options', 'pc-form-builder-xyz123' ); ?></label>
<textarea name="fields[<?php echo esc_attr( $index ); ?>][options]" rows="3" placeholder="<?php esc_attr_e( 'One option per line', 'pc-form-builder-xyz123' ); ?>"></textarea>
<p class="description"><?php esc_html_e( 'Enter each option on a new line.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php elseif ( 'checkbox' === $field_type ) : ?>
<div class="pcfb-form-group">
<label><?php esc_html_e( 'Checkbox Options', 'pc-form-builder-xyz123' ); ?></label>
<textarea name="fields[<?php echo esc_attr( $index ); ?>][options]" rows="3" placeholder="<?php esc_attr_e( 'One option per line', 'pc-form-builder-xyz123' ); ?>"></textarea>
<p class="description"><?php esc_html_e( 'Enter each checkbox option on a new line.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php endif; ?>
<div class="pcfb-form-group pcfb-validation-group">
<label class="pcfb-checkbox-label">
<input type="checkbox" name="fields[<?php echo esc_attr( $index ); ?>][validation_rules][required]" value="1">
<?php esc_html_e( 'Required field', 'pc-form-builder-xyz123' ); ?>
</label>
</div>
</div>
<div class="pcfb-field-footer">
<button type="button" class="button button-link-delete pcfb-delete-field"><?php esc_html_e( 'Remove Field', 'pc-form-builder-xyz123' ); ?></button>
</div>
</div>
<?php
}
}
if ( ! class_exists( 'PCFB_Field_Icons' ) ) {
class PCFB_Field_Icons {
private static $icons = array(
'text' => 'dashicons-text',
'email' => 'dashicons-email',
'name' => 'dashicons-admin-users',
'response' => 'dashicons-editor-quote',
'dropdown' => 'dashicons-arrow-down-alt2',
'checkbox' => 'dashicons-yes',
);
public static function get_field_icon( $type ) {
return isset( self::$icons[ $type ] ) ? self::$icons[ $type ] : 'dashicons-editor-help';
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,240 @@
/**
* PC Form Builder Admin Scripts
*
* JavaScript functionality for the form builder admin interface.
*
* @package PCFormBuilder
*/
(function($) {
'use strict';
var PCFB_Admin = {
fieldIndex: 0,
deletedFields: [],
init: function() {
this.initFieldTypeButtons();
this.initFieldToggle();
this.initFieldDelete();
this.initDeleteModal();
this.initFormBuilder();
},
initFieldTypeButtons: function() {
var self = this;
$('.pcfb-add-field-btn').on('click', function(e) {
e.preventDefault();
var fieldType = $(this).data('field-type');
self.addField(fieldType);
});
},
addField: function(fieldType) {
var self = this;
var container = $('#pcfb-fields-container');
if (container.find('.pcfb-empty-fields').length > 0) {
container.find('.pcfb-empty-fields').remove();
}
var fieldIndex = this.getNextFieldIndex();
var nonce = pcfbAdminVars.nonce;
$.ajax({
url: pcfbAdminVars.ajaxurl,
type: 'POST',
data: {
action: 'pcfb_add_field',
field_type: fieldType,
field_index: fieldIndex,
nonce: nonce
},
success: function(response) {
if (response.success) {
container.append(response.data.html);
self.reindexFields();
self.initFieldToggle();
self.initFieldDelete();
self.updateLabelOnChange();
}
},
error: function() {
alert(pcfbAdminVars.i18n.confirmDeleteField);
}
});
},
getNextFieldIndex: function() {
var maxIndex = 0;
$('#pcfb-fields-container [name^="fields["]').each(function() {
var match = $(this).attr('name').match(/fields\[(\d+)\]/);
if (match && parseInt(match[1]) > maxIndex) {
maxIndex = parseInt(match[1]);
}
});
return maxIndex + 1;
},
reindexFields: function() {
var fields = $('#pcfb-fields-container .pcfb-field-item');
fields.each(function(index) {
var field = $(this);
field.find('[name^="fields["]').each(function() {
var name = $(this).attr('name');
var newName = name.replace(/fields\[\d+\]/, 'fields[' + index + ']');
$(this).attr('name', newName);
});
});
},
initFieldToggle: function() {
$('.pcfb-toggle-field').off('click').on('click', function(e) {
e.preventDefault();
$(this).closest('.pcfb-field-item').toggleClass('collapsed');
});
},
initFieldDelete: function() {
var self = this;
$('.pcfb-delete-field').off('click').on('click', function(e) {
e.preventDefault();
var fieldItem = $(this).closest('.pcfb-field-item');
var fieldId = fieldItem.data('field-id');
if (confirm(pcfbAdminVars.i18n.confirmDeleteField)) {
if (fieldId && fieldId !== 'new') {
self.deletedFields.push(fieldId);
$('<input type="hidden" name="deleted_fields[]" value="' + fieldId + '">').appendTo('#pcfb-form-builder');
}
fieldItem.fadeOut(300, function() {
$(this).remove();
self.reindexFields();
self.checkEmptyFields();
});
}
});
},
checkEmptyFields: function() {
var container = $('#pcfb-fields-container');
if (container.find('.pcfb-field-item').length === 0) {
container.html('<div class="pcfb-empty-fields"><p>' + pcfbAdminVars.i18n.fieldLabel + '</p></div>');
}
},
updateLabelOnChange: function() {
$('.pcfb-field-label-input').off('input').on('input', function() {
var label = $(this).val();
var fieldItem = $(this).closest('.pcfb-field-item');
var fieldName = fieldItem.find('.pcfb-field-name-display');
var baseName = this.getAttribute('name').match(/fields\[(\d+)\]\[field_label\]/);
if (baseName) {
var slug = label.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '');
if (slug === '') {
slug = 'field_' + baseName[1];
}
fieldName.text(slug);
var hiddenName = fieldItem.find('input[name^="fields["][name$="[field_name]"]');
hiddenName.val(slug);
}
});
},
initDeleteModal: function() {
var self = this;
$(document).on('click', '.pcfb-delete-form, .pcfb-delete-form-btn, .pcfb-delete-form-link', function(e) {
if (e.target.tagName === 'BUTTON' || $(this).hasClass('pcfb-delete-form') || $(this).hasClass('pcfb-delete-form-btn') || $(this).hasClass('pcfb-delete-form-link')) {
e.preventDefault();
var formId = $(this).data('form-id');
var formName = $(this).data('form-name');
$('#pcfb-delete-form-id').val(formId);
$('#pcfb-delete-form-name').text(formName);
$('#pcfb-delete-modal').addClass('active').show();
}
});
$('.pcfb-modal-close, .pcfb-modal-cancel').on('click', function(e) {
e.preventDefault();
$('#pcfb-delete-modal').removeClass('active').hide();
});
$('#pcfb-delete-modal').on('click', function(e) {
if ($(e.target).is('#pcfb-delete-modal')) {
$(this).removeClass('active').hide();
}
});
},
initFormBuilder: function() {
var self = this;
if ($('#pcfb-fields-container').length > 0) {
$('#pcfb-fields-container').sortable({
handle: '.pcfb-field-header',
placeholder: 'pcfb-field-placeholder',
tolerance: 'pointer',
update: function() {
self.reindexFields();
}
});
}
if ($('#pcfb-sections-container').length > 0) {
$('#pcfb-sections-container').sortable({
handle: '.pcfb-section-header',
placeholder: 'pcfb-section-placeholder',
tolerance: 'pointer'
});
}
$('#pcfb-add-section').on('click', function(e) {
e.preventDefault();
self.addSection();
});
$('#pcfb-form-builder').on('submit', function(e) {
var formName = $('#form-name').val().trim();
if (!formName) {
e.preventDefault();
alert(pcfbAdminVars.i18n.fieldLabel);
$('#form-name').focus();
return false;
}
var hasRequiredFields = false;
$('.pcfb-field-item').each(function() {
if ($(this).find('[name*="[validation_rules][required]"]').is(':checked')) {
hasRequiredFields = true;
}
});
});
},
addSection: function() {
var container = $('#pcfb-sections-container');
var sectionCount = container.find('.pcfb-section-box').length;
var sectionHtml = '<div class="pcfb-section-box" data-section-id="new-' + sectionCount + '">' +
'<div class="pcfb-section-header">' +
'<span class="dashicons dashicons-menu"></span>' +
'<span class="pcfb-section-title">Section ' + (sectionCount + 1) + '</span>' +
'</div>' +
'<div class="pcfb-section-content">' +
'<input type="hidden" name="sections[' + sectionCount + '][id]" value="">' +
'<input type="hidden" name="sections[' + sectionCount + '][title]" value="Section ' + (sectionCount + 1) + '">' +
'<p class="description">Drag fields into this section or click to configure.</p>' +
'</div>' +
'</div>';
container.append(sectionHtml);
}
};
$(document).ready(function() {
PCFB_Admin.init();
});
})(jQuery);

View File

@@ -0,0 +1,195 @@
<div class="wrap pcfb-wrap">
<h1 class="wp-heading-inline">
<span class="pcfb-heading-icon dashicons dashicons-forms"></span>
<?php esc_html_e( 'All Forms', 'pc-form-builder-xyz123' ); ?>
</h1>
<a href="<?php echo admin_url( 'admin.php?page=pcfb-form-builder' ); ?>" class="page-title-action">
<span class="dashicons dashicons-plus"></span>
<?php esc_html_e( 'Add New Form', 'pc-form-builder-xyz123' ); ?>
</a>
<hr class="wp-header-end">
<?php
$forms = PC_Form_Handler::get_forms( array( 'limit' => 50, 'status' => '' ) );
$active_count = PC_Form_Handler::get_form_count( 'active' );
$inactive_count = PC_Form_Handler::get_form_count( 'inactive' );
$total_responses = 0;
foreach ( $forms as $form ) {
$total_responses += PC_Form_Handler::get_form_response_count( $form->id );
}
?>
<div class="pcfb-all-forms-page">
<div class="pcfb-stats-row">
<div class="pcfb-stat-card">
<div class="pcfb-stat-icon pcfb-stat-icon-blue">
<span class="dashicons dashicons-forms"></span>
</div>
<div class="pcfb-stat-content">
<span class="pcfb-stat-number"><?php echo esc_html( count( $forms ) ); ?></span>
<span class="pcfb-stat-label"><?php esc_html_e( 'Total Forms', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
<div class="pcfb-stat-card">
<div class="pcfb-stat-icon pcfb-stat-icon-green">
<span class="dashicons dashicons-yes-alt"></span>
</div>
<div class="pcfb-stat-content">
<span class="pcfb-stat-number"><?php echo esc_html( $active_count ); ?></span>
<span class="pcfb-stat-label"><?php esc_html_e( 'Active Forms', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
<div class="pcfb-stat-card">
<div class="pcfb-stat-icon pcfb-stat-icon-orange">
<span class="dashicons dashicons-hidden"></span>
</div>
<div class="pcfb-stat-content">
<span class="pcfb-stat-number"><?php echo esc_html( $inactive_count ); ?></span>
<span class="pcfb-stat-label"><?php esc_html_e( 'Inactive Forms', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
<div class="pcfb-stat-card">
<div class="pcfb-stat-icon pcfb-stat-icon-purple">
<span class="dashicons dashicons-pressthis"></span>
</div>
<div class="pcfb-stat-content">
<span class="pcfb-stat-number"><?php echo esc_html( $total_responses ); ?></span>
<span class="pcfb-stat-label"><?php esc_html_e( 'Total Signups', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
</div>
<?php if ( empty( $forms ) ) : ?>
<div class="pcfb-empty-state">
<span class="dashicons dashicons-forms pcfb-empty-icon"></span>
<h3><?php esc_html_e( 'No forms created yet', 'pc-form-builder-xyz123' ); ?></h3>
<p><?php esc_html_e( 'Create your first form to start collecting responses from your visitors.', 'pc-form-builder-xyz123' ); ?></p>
<a href="<?php echo admin_url( 'admin.php?page=pcfb-form-builder' ); ?>" class="button button-primary">
<?php esc_html_e( 'Create Your First Form', 'pc-form-builder-xyz123' ); ?>
</a>
</div>
<?php else : ?>
<div class="pcfb-forms-table-card">
<div class="pcfb-card-header pcfb-table-header">
<h2><?php esc_html_e( 'Your Forms', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<table class="widefat pcfb-table pcfb-forms-table">
<thead>
<tr>
<th class="column-primary"><?php esc_html_e( 'Form Name', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Shortcode', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Fields', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Signups', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Status', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Created', 'pc-form-builder-xyz123' ); ?></th>
<th class="column-actions"><?php esc_html_e( 'Actions', 'pc-form-builder-xyz123' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $forms as $form ) : ?>
<?php
$field_count = pcfb_get_field_count( $form->id );
$response_count = PC_Form_Handler::get_form_response_count( $form->id );
$edit_url = admin_url( 'admin.php?page=pcfb-form-builder&form_id=' . $form->id );
$responses_url = admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form->id );
$status_class = 'active' === $form->status ? 'status-active' : 'status-inactive';
$status_text = 'active' === $form->status ? __( 'Active', 'pc-form-builder-xyz123' ) : __( 'Inactive', 'pc-form-builder-xyz123' );
?>
<tr>
<td class="column-primary">
<strong>
<a href="<?php echo esc_url( $edit_url ); ?>">
<?php echo esc_html( $form->name ); ?>
</a>
</strong>
<div class="row-actions">
<span class="edit"><a href="<?php echo esc_url( $edit_url ); ?>"><?php esc_html_e( 'Edit', 'pc-form-builder-xyz123' ); ?></a> | </span>
<span class="responses"><a href="<?php echo esc_url( $responses_url ); ?>"><?php esc_html_e( 'Responses', 'pc-form-builder-xyz123' ); ?></a> | </span>
<span class="delete"><button type="button" class="pcfb-delete-form-link" data-form-id="<?php echo esc_attr( $form->id ); ?>" data-form-name="<?php echo esc_attr( $form->name ); ?>"><?php esc_html_e( 'Delete', 'pc-form-builder-xyz123' ); ?></button></span>
</div>
<?php if ( $form->description ) : ?>
<br>
<small class="description"><?php echo esc_html( $form->description ); ?></small>
<?php endif; ?>
</td>
<td data-colname="<?php esc_attr_e( 'Shortcode', 'pc-form-builder-xyz123' ); ?>">
<code class="pcfb-shortcode" onclick="this.select(); document.execCommand('copy');" title="<?php esc_attr_e( 'Click to copy', 'pc-form-builder-xyz123' ); ?>">
[pcfb-form id="<?php echo esc_attr( $form->id ); ?>"]
</code>
</td>
<td data-colname="<?php esc_attr_e( 'Fields', 'pc-form-builder-xyz123' ); ?>">
<span class="pcfb-field-badge"><?php echo esc_html( $field_count ); ?></span>
</td>
<td data-colname="<?php esc_attr_e( 'Signups', 'pc-form-builder-xyz123' ); ?>">
<?php if ( $response_count > 0 ) : ?>
<a href="<?php echo esc_url( $responses_url ); ?>" class="pcfb-signups-link">
<span class="pcfb-signup-count"><?php echo esc_html( $response_count ); ?></span>
</a>
<?php else : ?>
<span class="pcfb-signup-count zero"><?php echo esc_html( $response_count ); ?></span>
<?php endif; ?>
</td>
<td data-colname="<?php esc_attr_e( 'Status', 'pc-form-builder-xyz123' ); ?>">
<span class="pcfb-status <?php echo esc_attr( $status_class ); ?>">
<?php echo esc_html( $status_text ); ?>
</span>
</td>
<td data-colname="<?php esc_attr_e( 'Created', 'pc-form-builder-xyz123' ); ?>">
<?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $form->created_at ) ) ); ?>
</td>
<td class="column-actions" data-colname="<?php esc_attr_e( 'Actions', 'pc-form-builder-xyz123' ); ?>">
<div class="pcfb-actions">
<a href="<?php echo esc_url( $edit_url ); ?>" class="button button-small" title="<?php esc_attr_e( 'Edit Form', 'pc-form-builder-xyz123' ); ?>">
<span class="dashicons dashicons-edit"></span>
</a>
<a href="<?php echo esc_url( $responses_url ); ?>" class="button button-small" title="<?php esc_attr_e( 'View Responses', 'pc-form-builder-xyz123' ); ?>">
<span class="dashicons dashicons-pressthis"></span>
</a>
<button type="button" class="button button-small pcfb-delete-form" data-form-id="<?php echo esc_attr( $form->id ); ?>" data-form-name="<?php echo esc_attr( $form->name ); ?>" title="<?php esc_attr_e( 'Delete Form', 'pc-form-builder-xyz123' ); ?>">
<span class="dashicons dashicons-trash"></span>
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<div id="pcfb-delete-modal" class="pcfb-modal" style="display: none;">
<div class="pcfb-modal-content">
<div class="pcfb-modal-header">
<h3><?php esc_html_e( 'Delete Form', 'pc-form-builder-xyz123' ); ?></h3>
<button type="button" class="pcfb-modal-close">&times;</button>
</div>
<div class="pcfb-modal-body">
<p><?php esc_html_e( 'Are you sure you want to delete this form? All responses will also be deleted. This action cannot be undone.', 'pc-form-builder-xyz123' ); ?></p>
<p><strong id="pcfb-delete-form-name"></strong></p>
</div>
<div class="pcfb-modal-footer">
<form method="post" id="pcfb-delete-form">
<?php wp_nonce_field( 'pcfb_admin_action', '_wpnonce' ); ?>
<input type="hidden" name="pcfb_action" value="delete_form">
<input type="hidden" name="form_id" id="pcfb-delete-form-id" value="">
<button type="button" class="button pcfb-modal-cancel"><?php esc_html_e( 'Cancel', 'pc-form-builder-xyz123' ); ?></button>
<button type="submit" class="button button-primary"><?php esc_html_e( 'Delete Form', 'pc-form-builder-xyz123' ); ?></button>
</form>
</div>
</div>
</div>
</div>
<?php
function pcfb_get_field_count( $form_id ) {
global $wpdb;
$table_name = $wpdb->prefix . 'pcfb_fields';
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table_name} WHERE form_id = %d", $form_id ) );
}
?>

View File

@@ -0,0 +1,199 @@
<div class="wrap pcfb-wrap">
<h1 class="wp-heading-inline">
<span class="pcfb-heading-icon dashicons dashicons-feedback"></span>
<?php esc_html_e( 'Form Builder', 'pc-form-builder-xyz123' ); ?>
</h1>
<a href="<?php echo admin_url( 'admin.php?page=pcfb-all-forms' ); ?>" class="page-title-action">
<span class="dashicons dashicons-list-view"></span>
<?php esc_html_e( 'All Forms', 'pc-form-builder-xyz123' ); ?>
</a>
<hr class="wp-header-end">
<?php
require_once PCFB_PLUGIN_DIR . 'admin/class-admin-helper.php';
$helper = PCFB_Admin_Helper::get_instance();
$form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
$is_new = $form_id === 0;
if ( ! $is_new ) {
$form = PC_Form_Handler::get_form_by_id( $form_id );
if ( ! $form ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Form not found.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$fields = $helper->get_form_fields( $form_id );
$settings = maybe_unserialize( $form->settings );
} else {
$form = (object) array(
'id' => 0,
'name' => '',
'description' => '',
'status' => 'active',
'settings' => array(),
);
$fields = array();
$settings = array();
}
$field_types = $helper->get_field_types();
?>
<?php if ( ! $is_new ) : ?>
<div class="pcfb-shortcode-notice" style="background: #f0f0f1; border: 1px solid #c3c4c7; border-radius: 6px; padding: 15px 20px; margin-bottom: 20px; display: flex; align-items: center; gap: 15px;">
<span class="dashicons dashicons-shortcode" style="color: #2271b1; font-size: 24px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;"></span>
<div style="flex: 1;">
<strong style="display: block; margin-bottom: 4px;"><?php esc_html_e( 'Form Shortcode', 'pc-form-builder-xyz123' ); ?></strong>
<code onclick="this.select(); document.execCommand('copy');" style="background: #fff; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 14px; display: inline-block;">[pcfb-form id="<?php echo esc_attr( $form->id ); ?>"]</code>
<span class="description" style="display: block; margin-top: 4px; font-size: 12px;"><?php esc_html_e( 'Click the shortcode to copy it', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
<?php endif; ?>
<form method="post" id="pcfb-form-builder" class="pcfb-form-builder">
<?php wp_nonce_field( 'pcfb_admin_action', '_wpnonce' ); ?>
<input type="hidden" name="pcfb_action" value="save_form">
<input type="hidden" name="form[id]" value="<?php echo esc_attr( $form->id ); ?>">
<div class="pcfb-builder-layout">
<div class="pcfb-builder-main">
<div class="pcfb-card pcfb-form-settings-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Form Details', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<div class="pcfb-form-group">
<label for="form-name"><?php esc_html_e( 'Form Name', 'pc-form-builder-xyz123' ); ?> *</label>
<input type="text" id="form-name" name="form[name]" value="<?php echo esc_attr( $form->name ); ?>" required placeholder="<?php esc_attr_e( 'Enter form name', 'pc-form-builder-xyz123' ); ?>">
</div>
<div class="pcfb-form-group">
<label for="form-description"><?php esc_html_e( 'Description', 'pc-form-builder-xyz123' ); ?></label>
<textarea id="form-description" name="form[description]" rows="2" placeholder="<?php esc_attr_e( 'Brief description of this form', 'pc-form-builder-xyz123' ); ?>"><?php echo esc_textarea( $form->description ); ?></textarea>
</div>
<div class="pcfb-form-group">
<label for="form-status"><?php esc_html_e( 'Status', 'pc-form-builder-xyz123' ); ?></label>
<select id="form-status" name="form[status]">
<option value="active" <?php selected( $form->status, 'active' ); ?>><?php esc_html_e( 'Active', 'pc-form-builder-xyz123' ); ?></option>
<option value="inactive" <?php selected( $form->status, 'inactive' ); ?>><?php esc_html_e( 'Inactive', 'pc-form-builder-xyz123' ); ?></option>
</select>
</div>
</div>
</div>
<div class="pcfb-card pcfb-fields-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Form Fields', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-field-types-section">
<h3><?php esc_html_e( 'Add Fields to Your Form', 'pc-form-builder-xyz123' ); ?></h3>
<p class="description"><?php esc_html_e( 'Click on any field type below to add it to your form. You can then customize the label, placeholder, and other options.', 'pc-form-builder-xyz123' ); ?></p>
<div class="pcfb-field-type-buttons">
<?php foreach ( $field_types as $type => $label ) : ?>
<button type="button" class="pcfb-add-field-btn" data-field-type="<?php echo esc_attr( $type ); ?>">
<span class="dashicons <?php echo esc_attr( PCFB_Field_Icons::get_field_icon( $type ) ); ?>"></span>
<span class="pcfb-field-label"><?php echo esc_html( $label ); ?></span>
</button>
<?php endforeach; ?>
</div>
</div>
<div class="pcfb-form-fields">
<h3><?php esc_html_e( 'Form Structure', 'pc-form-builder-xyz123' ); ?></h3>
<p class="description"><?php esc_html_e( 'Drag and drop fields to reorder them. Click on a field to expand and edit its properties.', 'pc-form-builder-xyz123' ); ?></p>
<div id="pcfb-fields-container" class="pcfb-fields-container">
<?php if ( empty( $fields ) ) : ?>
<div class="pcfb-empty-fields">
<span class="dashicons dashicons-plus-alt2 pcfb-empty-icon"></span>
<p><?php esc_html_e( 'No fields added yet.', 'pc-form-builder-xyz123' ); ?></p>
<p class="description"><?php esc_html_e( 'Click a field type above to start building your form.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php else : ?>
<?php foreach ( $fields as $index => $field ) : ?>
<?php echo $helper->render_field_item( $field, $index ); ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="pcfb-card pcfb-sections-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Form Sections', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<p class="description"><?php esc_html_e( 'Organize your form fields into sections for better user experience.', 'pc-form-builder-xyz123' ); ?></p>
<div id="pcfb-sections-container" class="pcfb-sections-container">
<div class="pcfb-section-box pcfb-default-section">
<div class="pcfb-section-header">
<span class="dashicons dashicons-menu"></span>
<span class="pcfb-section-title"><?php esc_html_e( 'Default Section', 'pc-form-builder-xyz123' ); ?></span>
</div>
<div class="pcfb-section-content">
<p class="description"><?php esc_html_e( 'All fields are placed in this default section by default. You can add section breaks between fields.', 'pc-form-builder-xyz123' ); ?></p>
</div>
</div>
</div>
<button type="button" class="button pcfb-add-section-btn" id="pcfb-add-section">
<span class="dashicons dashicons-plus"></span>
<?php esc_html_e( 'Add Section', 'pc-form-builder-xyz123' ); ?>
</button>
</div>
</div>
</div>
<div class="pcfb-builder-sidebar">
<div class="pcfb-card pcfb-publish-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Publish', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<button type="submit" class="button button-primary button-large pcfb-save-btn">
<span class="dashicons dashicons-saved"></span>
<?php esc_html_e( 'Save Form', 'pc-form-builder-xyz123' ); ?>
</button>
<a href="<?php echo admin_url( 'admin.php?page=pcfb-all-forms' ); ?>" class="button button-large">
<?php esc_html_e( 'Cancel', 'pc-form-builder-xyz123' ); ?>
</a>
</div>
</div>
<div class="pcfb-card pcfb-settings-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Form Settings', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<div class="pcfb-form-group">
<label for="form-success-message"><?php esc_html_e( 'Success Message', 'pc-form-builder-xyz123' ); ?></label>
<textarea id="form-success-message" name="form[settings][success_message]" rows="3" placeholder="<?php esc_attr_e( 'Thank you! Your response has been submitted.', 'pc-form-builder-xyz123' ); ?>"><?php echo isset( $settings['success_message'] ) ? esc_textarea( $settings['success_message'] ) : ''; ?></textarea>
</div>
<div class="pcfb-form-group">
<label for="form-submit-text"><?php esc_html_e( 'Submit Button Text', 'pc-form-builder-xyz123' ); ?></label>
<input type="text" id="form-submit-text" name="form[settings][submit_text]" value="<?php echo isset( $settings['submit_text'] ) ? esc_attr( $settings['submit_text'] ) : __( 'Submit', 'pc-form-builder-xyz123' ); ?>">
</div>
</div>
</div>
<div class="pcfb-card pcfb-help-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Quick Tips', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<p><strong><?php esc_html_e( 'Available Field Types:', 'pc-form-builder-xyz123' ); ?></strong></p>
<ul>
<li><span class="dashicons dashicons-text"></span> <strong><?php esc_html_e( 'Text', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Single line text input', 'pc-form-builder-xyz123' ); ?></li>
<li><span class="dashicons dashicons-email"></span> <strong><?php esc_html_e( 'Email', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Email address with validation', 'pc-form-builder-xyz123' ); ?></li>
<li><span class="dashicons dashicons-admin-users"></span> <strong><?php esc_html_e( 'Name', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Full name field', 'pc-form-builder-xyz123' ); ?></li>
<li><span class="dashicons dashicons-editor-quote"></span> <strong><?php esc_html_e( 'Response', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Multi-line textarea for responses', 'pc-form-builder-xyz123' ); ?></li>
<li><span class="dashicons dashicons-arrow-down-alt2"></span> <strong><?php esc_html_e( 'Dropdown', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Select from predefined options', 'pc-form-builder-xyz123' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <strong><?php esc_html_e( 'Checkbox', 'pc-form-builder-xyz123' ); ?></strong> - <?php esc_html_e( 'Checkbox options', 'pc-form-builder-xyz123' ); ?></li>
</ul>
<hr>
<p><?php esc_html_e( 'After saving, use the shortcode to embed this form on any page or post.', 'pc-form-builder-xyz123' ); ?></p>
</div>
</div>
</div>
</div>
</form>
</div>

View File

@@ -0,0 +1,111 @@
<div class="wrap pcfb-wrap">
<?php
$form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
if ( empty( $form_id ) ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Form ID is required.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$form = PC_Form_Handler::get_form_by_id( $form_id );
if ( ! $form ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Form not found.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$paged = isset( $_GET['paged'] ) ? max( 1, intval( $_GET['paged'] ) ) : 1;
$per_page = 20;
$offset = ( $paged - 1 ) * $per_page;
$responses = PC_Form_Handler::get_form_responses( $form_id, array(
'limit' => $per_page,
'offset' => $offset,
) );
$total_responses = PC_Form_Handler::get_form_response_count( $form_id );
$total_pages = ceil( $total_responses / $per_page );
?>
<h1 class="wp-heading-inline">
<a href="<?php echo admin_url( 'admin.php?page=pcfb-responses' ); ?>" class="pcfb-back-link">
<span class="dashicons dashicons-arrow-left-alt2"></span>
</a>
<span class="pcfb-heading-icon dashicons dashicons-pressthis"></span>
<?php echo esc_html( $form->name ); ?> - <?php esc_html_e( 'Responses', 'pc-form-builder-xyz123' ); ?>
</h1>
<span class="title-ext">
<?php echo esc_html( $total_responses . ' ' . _n( 'Response', 'Responses', $total_responses, 'pc-form-builder-xyz123' ) ); ?>
</span>
<hr class="wp-header-end">
<div class="pcfb-form-responses-page">
<?php if ( empty( $responses ) ) : ?>
<div class="pcfb-empty-state">
<span class="dashicons dashicons-pressthis pcfb-empty-icon"></span>
<h3><?php esc_html_e( 'No responses yet', 'pc-form-builder-xyz123' ); ?></h3>
<p><?php esc_html_e( 'This form has not received any responses yet.', 'pc-form-builder-xyz123' ); ?></p>
</div>
<?php else : ?>
<div class="pcfb-responses-header">
<div class="pcfb-response-count-badge">
<span class="dashicons dashicons-pressthis"></span>
<?php echo esc_html( $total_responses . ' ' . _n( 'Response', 'Responses', $total_responses, 'pc-form-builder-xyz123' ) ); ?>
</div>
</div>
<table class="widefat pcfb-table pcfb-responses-table">
<thead>
<tr>
<th><?php esc_html_e( 'ID', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Submitted', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'IP Address', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Status', 'pc-form-builder-xyz123' ); ?></th>
<th><?php esc_html_e( 'Actions', 'pc-form-builder-xyz123' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $responses as $response ) : ?>
<?php
$detail_url = admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form_id . '&response_id=' . $response->id );
$status_class = 'new' === $response->status ? 'status-new' : 'status-read';
$status_label = 'new' === $response->status ? __( 'New', 'pc-form-builder-xyz123' ) : __( 'Read', 'pc-form-builder-xyz123' );
?>
<tr>
<td><?php echo esc_html( $response->id ); ?></td>
<td><?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $response->created_at ) ) ); ?></td>
<td><?php echo esc_html( $response->user_ip ); ?></td>
<td>
<span class="pcfb-status <?php echo esc_attr( $status_class ); ?>">
<?php echo esc_html( $status_label ); ?>
</span>
</td>
<td>
<a href="<?php echo esc_url( $detail_url ); ?>" class="button button-small">
<?php esc_html_e( 'View Details', 'pc-form-builder-xyz123' ); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if ( $total_pages > 1 ) : ?>
<div class="pcfb-pagination">
<?php
echo paginate_links( array(
'base' => admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form_id . '&paged=%#%' ),
'format' => '',
'prev_text' => __( '&laquo; Previous', 'pc-form-builder-xyz123' ),
'next_text' => __( 'Next &raquo;', 'pc-form-builder-xyz123' ),
'total' => $total_pages,
'current' => $paged,
) );
?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>

View File

@@ -0,0 +1,118 @@
<div class="wrap pcfb-wrap">
<?php
$form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0;
$response_id = isset( $_GET['response_id'] ) ? intval( $_GET['response_id'] ) : 0;
if ( empty( $form_id ) || empty( $response_id ) ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Invalid request.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$form = PC_Form_Handler::get_form_by_id( $form_id );
if ( ! $form ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Form not found.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$response_data = PC_Form_Handler::get_response_data( $response_id );
if ( empty( $response_data ) ) {
echo '<div class="notice notice-error"><p>' . esc_html__( 'Response not found.', 'pc-form-builder-xyz123' ) . '</p></div>';
return;
}
$back_url = admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form_id );
$response_meta = pcfb_get_response_meta( $response_id );
?>
<h1 class="wp-heading-inline">
<a href="<?php echo esc_url( $back_url ); ?>" class="pcfb-back-link">
<span class="dashicons dashicons-arrow-left-alt2"></span>
</a>
<span class="pcfb-heading-icon dashicons dashicons-pressthis"></span>
<?php esc_html_e( 'Response Details', 'pc-form-builder-xyz123' ); ?>
</h1>
<span class="title-ext">
<?php esc_html_e( 'Response #', 'pc-form-builder-xyz123' ); ?><?php echo esc_html( $response_id ); ?>
</span>
<hr class="wp-header-end">
<div class="pcfb-response-detail-page">
<div class="pcfb-response-meta">
<div class="pcfb-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Response Information', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<table class="widefat pcfb-meta-table">
<tr>
<th><?php esc_html_e( 'Form:', 'pc-form-builder-xyz123' ); ?></th>
<td><?php echo esc_html( $form->name ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Submitted:', 'pc-form-builder-xyz123' ); ?></th>
<td><?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $response_meta['created_at'] ) ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'IP Address:', 'pc-form-builder-xyz123' ); ?></th>
<td><?php echo esc_html( $response_meta['user_ip'] ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'User Agent:', 'pc-form-builder-xyz123' ); ?></th>
<td><?php echo esc_html( $response_meta['user_agent'] ); ?></td>
</tr>
</table>
</div>
</div>
</div>
<div class="pcfb-response-content">
<div class="pcfb-card">
<div class="pcfb-card-header">
<h2><?php esc_html_e( 'Submitted Data', 'pc-form-builder-xyz123' ); ?></h2>
</div>
<div class="pcfb-card-body">
<?php foreach ( $response_data as $data ) : ?>
<div class="pcfb-response-field">
<div class="pcfb-response-field-label">
<?php echo esc_html( $data->field_label ); ?>
</div>
<div class="pcfb-response-field-value">
<?php
if ( 'checkbox' === $data->field_type ) {
$options = maybe_unserialize( $data->field_value );
if ( is_array( $options ) ) {
echo esc_html( implode( ', ', $options ) );
} else {
echo esc_html( $data->field_value );
}
} elseif ( 'response' === $data->field_type ) {
echo wpautop( esc_html( $data->field_value ) );
} else {
echo esc_html( $data->field_value );
}
?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<?php
function pcfb_get_response_meta( $response_id ) {
global $wpdb;
$table_name = $wpdb->prefix . 'pcfb_responses';
$response = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE id = %d", $response_id ), ARRAY_A );
return $response ? $response : array(
'user_ip' => '',
'user_agent' => '',
'created_at' => '',
);
}
?>

View File

@@ -0,0 +1,74 @@
<div class="wrap pcfb-wrap">
<h1 class="wp-heading-inline">
<span class="pcfb-heading-icon dashicons dashicons-pressthis"></span>
<?php esc_html_e( 'Form Responses', 'pc-form-builder-xyz123' ); ?>
</h1>
<hr class="wp-header-end">
<?php
$forms = PC_Form_Handler::get_forms( array( 'limit' => 100 ) );
?>
<div class="pcfb-responses-page">
<?php if ( empty( $forms ) ) : ?>
<div class="pcfb-empty-state">
<span class="dashicons dashicons-pressthis pcfb-empty-icon"></span>
<h3><?php esc_html_e( 'No forms to show responses', 'pc-form-builder-xyz123' ); ?></h3>
<p><?php esc_html_e( 'Create a form first to start collecting and viewing responses.', 'pc-form-builder-xyz123' ); ?></p>
<a href="<?php echo admin_url( 'admin.php?page=pcfb-form-builder&form_id=new' ); ?>" class="button button-primary">
<?php esc_html_e( 'Create a Form', 'pc-form-builder-xyz123' ); ?>
</a>
</div>
<?php else : ?>
<div class="pcfb-responses-overview">
<h2><?php esc_html_e( 'Select a Form', 'pc-form-builder-xyz123' ); ?></h2>
<p class="description"><?php esc_html_e( 'Choose a form to view its responses.', 'pc-form-builder-xyz123' ); ?></p>
<div class="pcfb-forms-select-list">
<?php foreach ( $forms as $form ) : ?>
<?php
$response_count = PC_Form_Handler::get_form_response_count( $form->id );
$view_url = admin_url( 'admin.php?page=pcfb-responses&form_id=' . $form->id );
$status_class = 'active' === $form->status ? 'status-active' : 'status-inactive';
?>
<div class="pcfb-form-select-item">
<div class="pcfb-form-select-info">
<h3>
<a href="<?php echo esc_url( $view_url ); ?>">
<?php echo esc_html( $form->name ); ?>
</a>
</h3>
<span class="pcfb-status <?php echo esc_attr( $status_class ); ?>">
<?php echo esc_html( 'active' === $form->status ? __( 'Active', 'pc-form-builder-xyz123' ) : __( 'Inactive', 'pc-form-builder-xyz123' ) ); ?>
</span>
</div>
<div class="pcfb-form-select-stats">
<span class="pcfb-response-count">
<strong><?php echo esc_html( $response_count ); ?></strong>
<?php echo _n( 'Response', 'Responses', $response_count, 'pc-form-builder-xyz123' ); ?>
</span>
<a href="<?php echo esc_url( $view_url ); ?>" class="button button-small">
<?php esc_html_e( 'View Responses', 'pc-form-builder-xyz123' ); ?>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="pcfb-total-responses">
<?php
$total_responses = 0;
foreach ( $forms as $form ) {
$total_responses += PC_Form_Handler::get_form_response_count( $form->id );
}
?>
<div class="pcfb-total-card">
<span class="pcfb-total-number"><?php echo esc_html( $total_responses ); ?></span>
<span class="pcfb-total-label"><?php esc_html_e( 'Total Responses Across All Forms', 'pc-form-builder-xyz123' ); ?></span>
</div>
</div>
<?php endif; ?>
</div>
</div>