Greatness

User banner image
User avatar
  • Greatness

function scholarship_renewal_form_shortcode() { ob_start(); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['scholarship_form_submitted'])) { if (!isset($_POST['scholarship_nonce']) || !wp_verify_nonce($_POST['scholarship_nonce'], 'submit_scholarship_form')) { echo 'Security check failed. Please try again.'; } else { // Sanitize form inputs $name = sanitize_text_field($_POST['name']); $current_level = sanitize_text_field($_POST['current_level']); $program = sanitize_text_field($_POST['program']); $initial_level = sanitize_text_field($_POST['initial_level']); $failed_courses = sanitize_text_field($_POST['failed_courses']); // Handle file upload if (!function_exists('wp_handle_upload')) { require_once(ABSPATH . 'wp-admin/includes/file.php'); } $uploadedfile = $_FILES['supporting_document']; $upload_overrides = ['test_form' => false]; $movefile = wp_handle_upload($uploadedfile, $upload_overrides); $file_url = $movefile && !isset($movefile['error']) ? $movefile['url'] : 'Upload failed.'; // Generate PDF (requires TCPDF or similar) require_once(plugin_dir_path(__FILE__) . 'tcpdf/tcpdf.php'); // Ensure TCPDF is installed $pdf = new TCPDF(); $pdf->AddPage(); $pdf->SetFont('helvetica', '', 12); $html = "Scholarship Renewal Submission Name: {$name} Current Academic Level: {$current_level} Program of Study: {$program} Initial Level: {$initial_level} Failed Any Course: {$failed_courses} Uploaded File: {$file_url}"; $pdf->writeHTML($html); $upload_dir = wp_upload_dir(); $pdf_path = $upload_dir['basedir'] . '/scholarship-renewal-' . time() . '.pdf'; $pdf->Output($pdf_path, 'F'); // Email to admin $to = get_option('admin_email'); $subject = 'Scholarship Renewal Submission'; $message = 'A new scholarship renewal form has been submitted. See the attached PDF.'; $headers = ['Content-Type: text/html; charset=UTF-8']; $attachments = [$pdf_path]; wp_mail($to, $subject, $message, $headers, $attachments); echo 'Form submitted and sent successfully to admin!'; } } ?> Full Name: Current Academic Level: Program of Study: Academic Level When You Became a Scholar: Did You Fail Any Course Last Session? -- Select -- No Yes Upload Supporting Document: Submit Form <?php return ob_get_clean(); } add_shortcode('scholarship_form', 'scholarship_renewal_form_shortcode');

Scholarship Renewal Form