Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/conference/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/conference/test_form_fix.php

<?php
require_once 'includes/functions.php';

$eventId = 1;
$db = new CopMadinaDB();
$conn = $db->getConnection();

// Get event details
$stmt = $conn->prepare("SELECT * FROM events WHERE id = ?");
$stmt->execute([$eventId]);
$event = $stmt->fetch();

echo "<h2>Testing Form Field Name Generation</h2>";

// Get form template
if (!empty($event['form_template_id'])) {
    $stmt = $conn->prepare("SELECT form_fields FROM event_form_templates WHERE id = ? AND status = 'active'");
    $stmt->execute([$event['form_template_id']]);
    $template = $stmt->fetch();
    
    if ($template) {
        $formFields = json_decode($template['form_fields'], true) ?: [];
        
        echo "<h3>Original Template Fields:</h3>";
        echo "<pre>";
        print_r($formFields);
        echo "</pre>";
        
        // Apply the same fix as in register.php
        foreach ($formFields as &$field) {
            if (empty($field['name']) && !empty($field['label'])) {
                $field['name'] = strtolower(preg_replace('/[^a-zA-Z0-9\s]/', '', $field['label']));
                $field['name'] = preg_replace('/\s+/', '_', trim($field['name']));
            }
        }
        unset($field);
        
        echo "<h3>Fields After Name Generation:</h3>";
        echo "<pre>";
        print_r($formFields);
        echo "</pre>";
        
        echo "<h3>Generated Field Names:</h3>";
        echo "<ul>";
        foreach ($formFields as $field) {
            echo "<li><strong>" . htmlspecialchars($field['label']) . "</strong> → <code>" . htmlspecialchars($field['name']) . "</code></li>";
        }
        echo "</ul>";
    }
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists