208 lines
12 KiB
PHP
208 lines
12 KiB
PHP
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
|
|
|
$form_id = isset( $_GET['edit'] ) ? intval( $_GET['edit'] ) : 0;
|
|
$form = $form_id ? get_post( $form_id ) : null;
|
|
$meta = $form_id ? wmf_get_form_meta( $form_id ) : wmf_get_form_meta( 0 );
|
|
$title = $form ? $form->post_title : '';
|
|
$fields = $meta['fields'] ?? array();
|
|
$shortcode = $form_id ? wmf_get_shortcode( $form_id ) : '';
|
|
?>
|
|
<div class="wrap wmf-admin-wrap wmf-builder-wrap">
|
|
<h1 class="wmf-page-title">
|
|
<?php echo $form_id ? __( 'Formular bearbeiten', 'wp-multi-formular' ) : __( 'Neues Formular erstellen', 'wp-multi-formular' ); ?>
|
|
<?php if ( $shortcode ) : ?>
|
|
<span class="wmf-shortcode-badge" title="<?php esc_attr_e( 'Klicken zum Kopieren', 'wp-multi-formular' ); ?>">
|
|
<?php echo esc_html( $shortcode ); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</h1>
|
|
|
|
<form method="post" id="wmf-builder-form" action="<?php echo esc_url( admin_url( 'admin.php?page=wp-multi-formular' ) ); ?>">
|
|
<?php wp_nonce_field( 'wmf_save_form' ); ?>
|
|
<input type="hidden" name="wmf_admin_action" value="save_form">
|
|
<input type="hidden" name="form_id" value="<?php echo intval( $form_id ); ?>">
|
|
<input type="hidden" name="wmf_form_fields" id="wmf-form-fields-json" value="">
|
|
|
|
<!-- Formular-Titel -->
|
|
<div class="wmf-form-title-wrap">
|
|
<input type="text" name="form_title" id="wmf-form-title"
|
|
value="<?php echo esc_attr( $title ); ?>"
|
|
placeholder="<?php esc_attr_e( 'Formular-Titel …', 'wp-multi-formular' ); ?>"
|
|
class="wmf-title-input" required>
|
|
</div>
|
|
|
|
<div class="wmf-builder-layout">
|
|
|
|
<!-- Linke Spalte: Verfügbare Felder -->
|
|
<div class="wmf-field-palette">
|
|
<h3><?php _e( 'Felder hinzufügen', 'wp-multi-formular' ); ?></h3>
|
|
<div class="wmf-palette-search">
|
|
<input type="text" id="wmf-palette-search"
|
|
placeholder="<?php esc_attr_e( 'Feld suchen …', 'wp-multi-formular' ); ?>">
|
|
</div>
|
|
|
|
<?php
|
|
$categories = array(
|
|
'standard' => __( 'Standard', 'wp-multi-formular' ),
|
|
'auswahl' => __( 'Auswahl', 'wp-multi-formular' ),
|
|
'layout' => __( 'Layout', 'wp-multi-formular' ),
|
|
);
|
|
foreach ( $categories as $cat_key => $cat_label ) :
|
|
$cat_fields = array_filter( wmf_get_fields(), fn( $f ) => $f->category === $cat_key );
|
|
if ( empty( $cat_fields ) ) continue;
|
|
?>
|
|
<div class="wmf-palette-category">
|
|
<h4><?php echo esc_html( $cat_label ); ?></h4>
|
|
<div class="wmf-palette-fields">
|
|
<?php foreach ( $cat_fields as $field_obj ) : ?>
|
|
<div class="wmf-palette-field"
|
|
data-type="<?php echo esc_attr( $field_obj->type ); ?>"
|
|
data-label="<?php echo esc_attr( $field_obj->label ); ?>"
|
|
draggable="true">
|
|
<span class="dashicons <?php echo esc_attr( $field_obj->icon ); ?>"></span>
|
|
<?php echo esc_html( $field_obj->label ); ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<!-- Mittlere Spalte: Formular-Canvas -->
|
|
<div class="wmf-canvas-wrap">
|
|
<div class="wmf-canvas" id="wmf-canvas"
|
|
data-fields="<?php echo esc_attr( wp_json_encode( $fields ) ); ?>">
|
|
<div class="wmf-canvas-empty" id="wmf-canvas-empty">
|
|
<span class="dashicons dashicons-plus-alt2"></span>
|
|
<p><?php _e( 'Felder hierher ziehen oder links anklicken', 'wp-multi-formular' ); ?></p>
|
|
</div>
|
|
<div id="wmf-field-list" class="wmf-field-list"></div>
|
|
</div>
|
|
|
|
<!-- Speichern-Button -->
|
|
<div class="wmf-builder-save-bar">
|
|
<button type="submit" class="button button-primary button-large">
|
|
<?php _e( '✓ Formular speichern', 'wp-multi-formular' ); ?>
|
|
</button>
|
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wp-multi-formular' ) ); ?>"
|
|
class="button button-secondary button-large">
|
|
<?php _e( 'Abbrechen', 'wp-multi-formular' ); ?>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Rechte Spalte: Feld-Einstellungen + Formular-Optionen -->
|
|
<div class="wmf-settings-panel" id="wmf-settings-panel">
|
|
|
|
<!-- Feld-Einstellungen (dynamisch per JS) -->
|
|
<div id="wmf-field-settings" class="wmf-panel wmf-panel-field" style="display:none;">
|
|
<h3><?php _e( 'Feld-Einstellungen', 'wp-multi-formular' ); ?></h3>
|
|
<div id="wmf-field-settings-content"></div>
|
|
<hr>
|
|
<button type="button" class="button wmf-delete-field-btn">
|
|
🗑 <?php _e( 'Feld löschen', 'wp-multi-formular' ); ?>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Formular-Einstellungen -->
|
|
<div id="wmf-form-settings" class="wmf-panel wmf-panel-form">
|
|
<div class="wmf-tabs">
|
|
<button type="button" class="wmf-tab active" data-tab="allgemein"><?php _e( 'Allgemein', 'wp-multi-formular' ); ?></button>
|
|
<button type="button" class="wmf-tab" data-tab="email"><?php _e( 'E-Mails', 'wp-multi-formular' ); ?></button>
|
|
<button type="button" class="wmf-tab" data-tab="erweitert"><?php _e( 'Erweitert', 'wp-multi-formular' ); ?></button>
|
|
</div>
|
|
|
|
<!-- Tab: Allgemein -->
|
|
<div class="wmf-tab-content active" data-tab="allgemein">
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Button-Beschriftung', 'wp-multi-formular' ); ?></label>
|
|
<input type="text" name="submit_label"
|
|
value="<?php echo esc_attr( $meta['submit_label'] ); ?>" class="widefat">
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Erfolgsmeldung', 'wp-multi-formular' ); ?></label>
|
|
<textarea name="success_message" class="widefat" rows="3"><?php echo esc_textarea( $meta['success_message'] ); ?></textarea>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Fehlermeldung', 'wp-multi-formular' ); ?></label>
|
|
<textarea name="error_message" class="widefat" rows="3"><?php echo esc_textarea( $meta['error_message'] ); ?></textarea>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label>
|
|
<input type="checkbox" name="save_submissions" value="1" <?php checked( $meta['save_submissions'], '1' ); ?>>
|
|
<?php _e( 'Einreichungen in der Datenbank speichern', 'wp-multi-formular' ); ?>
|
|
</label>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label>
|
|
<input type="checkbox" name="recaptcha_enabled" value="1" <?php checked( $meta['recaptcha_enabled'], '1' ); ?>>
|
|
<?php _e( 'reCAPTCHA aktivieren', 'wp-multi-formular' ); ?>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab: E-Mails -->
|
|
<div class="wmf-tab-content" data-tab="email">
|
|
<h4><?php _e( 'Absender', 'wp-multi-formular' ); ?></h4>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Von: Name', 'wp-multi-formular' ); ?></label>
|
|
<input type="text" name="from_name" value="<?php echo esc_attr( $meta['from_name'] ); ?>" class="widefat">
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Von: E-Mail', 'wp-multi-formular' ); ?></label>
|
|
<input type="email" name="from_email" value="<?php echo esc_attr( $meta['from_email'] ); ?>" class="widefat">
|
|
</div>
|
|
<hr>
|
|
<h4><?php _e( 'Admin-Benachrichtigung', 'wp-multi-formular' ); ?></h4>
|
|
<div class="wmf-setting-group">
|
|
<label>
|
|
<input type="checkbox" name="notify_admin" value="1" <?php checked( $meta['notify_admin'], '1' ); ?>>
|
|
<?php _e( 'Admin per E-Mail benachrichtigen', 'wp-multi-formular' ); ?>
|
|
</label>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Admin-E-Mail', 'wp-multi-formular' ); ?></label>
|
|
<input type="email" name="admin_email" value="<?php echo esc_attr( $meta['admin_email'] ); ?>" class="widefat">
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Betreff', 'wp-multi-formular' ); ?></label>
|
|
<input type="text" name="admin_subject" value="<?php echo esc_attr( $meta['admin_subject'] ); ?>" class="widefat">
|
|
</div>
|
|
<hr>
|
|
<h4><?php _e( 'Absender-Bestätigung', 'wp-multi-formular' ); ?></h4>
|
|
<div class="wmf-setting-group">
|
|
<label>
|
|
<input type="checkbox" name="notify_sender" value="1" <?php checked( $meta['notify_sender'], '1' ); ?>>
|
|
<?php _e( 'Bestätigungs-E-Mail an Absender senden', 'wp-multi-formular' ); ?>
|
|
</label>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Betreff', 'wp-multi-formular' ); ?></label>
|
|
<input type="text" name="sender_subject" value="<?php echo esc_attr( $meta['sender_subject'] ); ?>" class="widefat">
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Nachricht', 'wp-multi-formular' ); ?></label>
|
|
<textarea name="sender_message" class="widefat" rows="4"><?php echo esc_textarea( $meta['sender_message'] ); ?></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab: Erweitert -->
|
|
<div class="wmf-tab-content" data-tab="erweitert">
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'Weiterleitungs-URL nach Absenden', 'wp-multi-formular' ); ?></label>
|
|
<input type="url" name="redirect_url" value="<?php echo esc_attr( $meta['redirect_url'] ); ?>"
|
|
class="widefat" placeholder="https://…">
|
|
<p class="description"><?php _e( 'Leer lassen, um die Erfolgsmeldung anzuzeigen.', 'wp-multi-formular' ); ?></p>
|
|
</div>
|
|
<div class="wmf-setting-group">
|
|
<label><?php _e( 'CSS-Klasse', 'wp-multi-formular' ); ?></label>
|
|
<input type="text" name="css_class" value="<?php echo esc_attr( $meta['css_class'] ); ?>" class="widefat">
|
|
</div>
|
|
</div>
|
|
</div><!-- #wmf-form-settings -->
|
|
|
|
</div><!-- .wmf-settings-panel -->
|
|
</div><!-- .wmf-builder-layout -->
|
|
</form>
|
|
</div>
|