add big filed
This commit is contained in:
@@ -20,7 +20,8 @@ CREATE TABLE wp_go_form_entries (
|
||||
created_at date DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (form_id) REFERENCES wp_go_form_forms(id) ON DELETE CASCADE,
|
||||
INDEX (form_id)
|
||||
INDEX (form_id),
|
||||
INDEX (egd_number)
|
||||
);
|
||||
|
||||
-- ========== Custom Fields Tables ==========
|
||||
@@ -29,10 +30,11 @@ CREATE TABLE wp_go_form_custom_fields (
|
||||
id int NOT NULL AUTO_INCREMENT,
|
||||
form_id int NOT NULL,
|
||||
field_name varchar(100) NOT NULL,
|
||||
field_type enum('select','text','checkbox', 'email') NOT NULL DEFAULT 'text',
|
||||
field_type enum('select','text','checkbox', 'email', 'textarea') NOT NULL DEFAULT 'text',
|
||||
field_options text,
|
||||
is_public tinyint(1) NOT NULL DEFAULT 0,
|
||||
is_required tinyint(1) NOT NULL DEFAULT 0,
|
||||
is_full_width tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (form_id) REFERENCES wp_go_form_forms(id) ON DELETE CASCADE,
|
||||
INDEX (form_id)
|
||||
|
||||
@@ -34,17 +34,19 @@ function go_form_activate()
|
||||
created_at date DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (form_id) REFERENCES $forms(id) ON DELETE CASCADE,
|
||||
INDEX (form_id)
|
||||
INDEX (form_id),
|
||||
INDEX (egd_number)
|
||||
) $charset;");
|
||||
|
||||
dbDelta("CREATE TABLE $custom_fields (
|
||||
id int NOT NULL AUTO_INCREMENT,
|
||||
form_id int NOT NULL,
|
||||
field_name varchar(100) NOT NULL,
|
||||
field_type enum('select','text','checkbox', 'email') NOT NULL DEFAULT 'text',
|
||||
field_type enum('select','text','checkbox', 'email', 'textarea') NOT NULL DEFAULT 'text',
|
||||
field_options text,
|
||||
is_public tinyint(1) NOT NULL DEFAULT 0,
|
||||
is_required tinyint(1) NOT NULL DEFAULT 0,
|
||||
is_full_width tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (form_id) REFERENCES $forms(id) ON DELETE CASCADE,
|
||||
INDEX (form_id)
|
||||
@@ -352,6 +354,7 @@ function go_form_create_custom_field()
|
||||
$field_options = isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : '';
|
||||
$is_public = isset($_POST['is_public']) ? 1 : 0;
|
||||
$is_required = isset($_POST['is_required']) ? 1 : 0;
|
||||
$is_full_width = isset($_POST['is_full_width']) ? 1 : 0;
|
||||
|
||||
$wpdb->insert("{$wpdb->prefix}go_form_custom_fields", [
|
||||
'form_id' => $form_id,
|
||||
@@ -359,7 +362,8 @@ function go_form_create_custom_field()
|
||||
'field_type' => $field_type,
|
||||
'field_options' => $field_options,
|
||||
'is_public' => $is_public,
|
||||
'is_required' => $is_required
|
||||
'is_required' => $is_required,
|
||||
'is_full_width' => $is_full_width
|
||||
]);
|
||||
}
|
||||
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $_POST['form_id'], 'created_field' => 1), admin_url('admin.php'));
|
||||
@@ -379,13 +383,15 @@ function go_form_update_custom_field()
|
||||
$field_options = isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : '';
|
||||
$is_public = isset($_POST['is_public']) ? 1 : 0;
|
||||
$is_required = isset($_POST['is_required']) ? 1 : 0;
|
||||
$is_full_width = isset($_POST['is_full_width']) ? 1 : 0;
|
||||
|
||||
$wpdb->update("{$wpdb->prefix}go_form_custom_fields", [
|
||||
'field_name' => $field_name,
|
||||
'field_type' => $field_type,
|
||||
'field_options' => $field_options,
|
||||
'is_public' => $is_public,
|
||||
'is_required' => $is_required
|
||||
'is_required' => $is_required,
|
||||
'is_full_width' => $is_full_width
|
||||
], ['id' => $field_id]);
|
||||
}
|
||||
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $_POST['form_id'], 'updated_field' => 1), admin_url('admin.php'));
|
||||
@@ -397,9 +403,9 @@ add_action('admin_post_go_form_update_custom_field', 'go_form_update_custom_fiel
|
||||
function go_form_delete_custom_field()
|
||||
{
|
||||
go_form_admin_action('delete_custom_field');
|
||||
if (isset($_POST['field_id'])) {
|
||||
if (isset($_POST['value_one'])) {
|
||||
global $wpdb;
|
||||
$field_id = intval($_POST['field_id']);
|
||||
$field_id = intval($_POST['value_one']);
|
||||
$field = go_form_get_custom_field_by_id($field_id);
|
||||
$form_id = $field ? $field->form_id : 0;
|
||||
$wpdb->delete("{$wpdb->prefix}go_form_custom_fields", ['id' => $field_id]);
|
||||
|
||||
@@ -102,7 +102,19 @@
|
||||
<?php
|
||||
// Display custom fields
|
||||
$custom_fields = go_form_get_custom_fields($form_id);
|
||||
foreach ($custom_fields as $field):
|
||||
$full_width_fields = [];
|
||||
$grid_fields = [];
|
||||
|
||||
foreach ($custom_fields as $field) {
|
||||
if ($field->is_full_width) {
|
||||
$full_width_fields[] = $field;
|
||||
} else {
|
||||
$grid_fields[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
// Render grid fields
|
||||
foreach ($grid_fields as $field):
|
||||
$field_id = 'custom_field_' . $field->id;
|
||||
echo '<div' . ($field->field_type === 'checkbox' ? ' style="grid-column: span 2;"' : '') . '>';
|
||||
echo '<label for="' . esc_attr($field_id) . '">' . esc_html($field->field_name) . ($field->is_required ? '*' : '') . ':</label>';
|
||||
@@ -114,6 +126,9 @@
|
||||
case 'email':
|
||||
echo '<input type="email" name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '"' . ($field->is_required ? ' required' : '') . '>';
|
||||
break;
|
||||
case 'textarea':
|
||||
echo '<textarea name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" rows="4" style="width:100%;"' . ($field->is_required ? ' required' : '') . '></textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$options = $field->field_options ? explode(',', $field->field_options) : [];
|
||||
echo '<select name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '"' . ($field->is_required ? ' required' : '') . '>';
|
||||
@@ -134,6 +149,41 @@
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Render full-width fields outside the grid
|
||||
foreach ($full_width_fields as $field):
|
||||
$field_id = 'custom_field_' . $field->id;
|
||||
echo '<div style="grid-column: 1 / -1; margin-top: 10px;">';
|
||||
echo '<label for="' . esc_attr($field_id) . '">' . esc_html($field->field_name) . ($field->is_required ? '*' : '') . ':</label>';
|
||||
|
||||
switch ($field->field_type) {
|
||||
case 'text':
|
||||
echo '<input type="text" name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" style="width:100%;"' . ($field->is_required ? ' required' : '') . '>';
|
||||
break;
|
||||
case 'email':
|
||||
echo '<input type="email" name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" style="width:100%;"' . ($field->is_required ? ' required' : '') . '>';
|
||||
break;
|
||||
case 'textarea':
|
||||
echo '<textarea name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" rows="4" style="width:100%;"' . ($field->is_required ? ' required' : '') . '></textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$options = $field->field_options ? explode(',', $field->field_options) : [];
|
||||
echo '<select name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" style="width:100%;"' . ($field->is_required ? ' required' : '') . '>';
|
||||
echo '<option value="">-- Select --</option>';
|
||||
foreach ($options as $option) {
|
||||
$option = trim($option);
|
||||
echo '<option value="' . esc_attr($option) . '">' . esc_html($option) . '</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
break;
|
||||
case 'checkbox':
|
||||
echo '<input type="checkbox" name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" value="1"' . ($field->is_required ? ' required' : '') . '>';
|
||||
break;
|
||||
}
|
||||
echo '</div>';
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
<p>* Required fields</p>
|
||||
<input type="submit" name="go_form_submit" value="Submit">
|
||||
</form>
|
||||
|
||||
@@ -41,10 +41,10 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
echo '<div style="margin-bottom:15px; display: flex; flex-wrap: wrap; gap: 10px;">';
|
||||
|
||||
action_button('go_form_delete_form', 'Delete Form', 'Delete this form and ALL entries?', $selected_form_id);
|
||||
action_button('go_form_export_csv', 'Export to CSV', 'Confrm Export', $selected_form_id);
|
||||
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confrm Export', $selected_form_id);
|
||||
action_button('go_form_export_opengotha', 'Export to Opengoth', 'Confrm Export', $selected_form_id);
|
||||
action_button('go_form_export_mcmahon', 'Export to McMahon', 'Confrm Export', $selected_form_id);
|
||||
action_button('go_form_export_csv', 'Export to CSV', 'Confirm Export', $selected_form_id);
|
||||
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confirm Export', $selected_form_id);
|
||||
action_button('go_form_export_opengotha', 'Export to Opengoth', 'Confirm Export', $selected_form_id);
|
||||
action_button('go_form_export_mcmahon', 'Export to McMahon', 'Confirm Export', $selected_form_id);
|
||||
action_button('go_form_update_egd_data', 'Update EGD Data', 'Update rank and rating from EGD for all entries with EGD numbers?', $selected_form_id);
|
||||
|
||||
echo '</div>';
|
||||
@@ -69,11 +69,13 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
echo '<option value="select">Dropdown (Select)</option>';
|
||||
echo '<option value="checkbox">Checkbox</option>';
|
||||
echo '<option value="email">Email</option>';
|
||||
echo '<option value="textarea">Textarea</option>';
|
||||
echo '</select>';
|
||||
echo '</td></tr>';
|
||||
echo '<tr><th><label for="field_options">Options (for select, comma-separated):</label></th><td><textarea name="field_options" id="field_options" rows="2" style="width:100%;"></textarea><small>e.g., Option 1,Option 2,Option 3</small></td></tr>';
|
||||
echo '<tr><th><label for="is_public">Public:</label></th><td><input type="checkbox" name="is_public" id="is_public" value="1" checked> <small>Show on public form</small></td></tr>';
|
||||
echo '<tr><th><label for="is_required">Required:</label></th><td><input type="checkbox" name="is_required" id="is_required" value="1"> <small>Required field</small></td></tr>';
|
||||
echo '<tr><th><label for="is_full_width">Full Width:</label></th><td><input type="checkbox" name="is_full_width" id="is_full_width" value="1"> <small>Display on full width (outside grid)</small></td></tr>';
|
||||
echo '</table>';
|
||||
echo '<p class="submit"><input type="submit" class="button button-primary" value="Add Custom Field"></p>';
|
||||
echo '</form>';
|
||||
@@ -82,13 +84,14 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
// List existing custom fields
|
||||
if (!empty($custom_fields)) {
|
||||
echo '<table class="wp-list-table widefat striped" style="margin-top:15px;">';
|
||||
echo '<thead><tr><th>Field Name</th><th>Type</th><th>Public</th><th>Required</th><th>Actions</th></tr></thead><tbody>';
|
||||
echo '<thead><tr><th>Field Name</th><th>Type</th><th>Public</th><th>Required</th><th>Full Width</th><th>Actions</th></tr></thead><tbody>';
|
||||
foreach ($custom_fields as $field) {
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html($field->field_name) . '</td>';
|
||||
echo '<td>' . esc_html($field->field_type) . '</td>';
|
||||
echo '<td>' . ($field->is_public ? 'Yes' : 'No') . '</td>';
|
||||
echo '<td>' . ($field->is_required ? 'Yes' : 'No') . '</td>';
|
||||
echo '<td>' . ($field->is_full_width ? 'Yes' : 'No') . '</td>';
|
||||
echo '<td>';
|
||||
// Edit button (toggle to show edit form)
|
||||
echo '<a href="' . add_query_arg(array('page' => 'go-form-settings', 'form_id' => $selected_form_id, 'edit_field' => $field->id), admin_url('admin.php')) . '" class="button button-small">Edit</a> ';
|
||||
@@ -119,11 +122,13 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
echo '<option value="select"' . selected($edit_field->field_type, 'select', false) . '>Dropdown (Select)</option>';
|
||||
echo '<option value="checkbox"' . selected($edit_field->field_type, 'checkbox', false) . '>Checkbox</option>';
|
||||
echo '<option value="email"' . selected($edit_field->field_type, 'email', false) . '>Email</option>';
|
||||
echo '<option value="textarea"' . selected($edit_field->field_type, 'textarea', false) . '>Textarea</option>';
|
||||
echo '</select>';
|
||||
echo '</td></tr>';
|
||||
echo '<tr><th><label for="field_options">Options (for select, comma-separated):</label></th><td><textarea name="field_options" id="field_options" rows="2" style="width:100%;">' . esc_textarea($edit_field->field_options) . '</textarea><small>e.g., Option 1,Option 2,Option 3</small></td></tr>';
|
||||
echo '<tr><th><label for="is_public">Public:</label></th><td><input type="checkbox" name="is_public" id="is_public" value="1" ' . checked($edit_field->is_public, 1, false) . '> <small>Show on public form</small></td></tr>';
|
||||
echo '<tr><th><label for="is_required">Required:</label></th><td><input type="checkbox" name="is_required" id="is_required" value="1" ' . checked($edit_field->is_required, 1, false) . '> <small>Required field</small></td></tr>';
|
||||
echo '<tr><th><label for="is_full_width">Full Width:</label></th><td><input type="checkbox" name="is_full_width" id="is_full_width" value="1" ' . checked($edit_field->is_full_width, 1, false) . '> <small>Display on full width (outside grid)</small></td></tr>';
|
||||
echo '</table>';
|
||||
echo '<p class="submit"><input type="submit" class="button button-primary" value="Update Custom Field"> <a href="' . add_query_arg(array('page' => 'go-form-settings', 'form_id' => $selected_form_id), admin_url('admin.php')) . '" class="button">Cancel</a></p>';
|
||||
echo '</form>';
|
||||
@@ -175,6 +180,9 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
case 'email':
|
||||
echo '<input type="email" name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" value="' . esc_attr($value) . '"' . ($field->is_required ? ' required' : '') . '>';
|
||||
break;
|
||||
case 'textarea':
|
||||
echo '<textarea name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '" rows="4" style="width:100%;"' . ($field->is_required ? ' required' : '') . '>' . esc_textarea($value) . '</textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$options = $field->field_options ? explode(',', $field->field_options) : [];
|
||||
echo '<select name="' . esc_attr($field_id) . '" id="' . esc_attr($field_id) . '"' . ($field->is_required ? ' required' : '') . '>';
|
||||
|
||||
Reference in New Issue
Block a user