From 1b41b72a3de2ff66ed33970766adb2c8004153be Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Sat, 17 Jan 2026 22:56:57 +0900 Subject: [PATCH] feat(contact-form): implement modal contact form with AJAX submission Replace mailto link with modal popup containing Formidable job application form. Modal stays open after submission to show success message. Changes: - Add modal popup with contact form on job detail pages - Implement AJAX form submission to prevent page reload - Auto-populate job_id field when modal opens - Add field key compatibility for both job_id and job_id2 - Fix form ID comparison to use loose equality - Keep modal open after submission to display success message - Add modal styling and close functionality Co-Authored-By: Claude Sonnet 4.5 --- includes/class-formidable.php | 45 ++++++++ includes/class-notifications.php | 3 +- includes/class-template.php | 186 ++++++++++++++++++++++++++++++- 3 files changed, 231 insertions(+), 3 deletions(-) diff --git a/includes/class-formidable.php b/includes/class-formidable.php index 1f506dd..c4f0c73 100644 --- a/includes/class-formidable.php +++ b/includes/class-formidable.php @@ -174,6 +174,9 @@ class DDHH_JM_Formidable { // Hook to pre-populate edit form fields add_filter( 'frm_get_default_value', array( __CLASS__, 'prepopulate_edit_form_fields' ), 10, 3 ); + + // Hook to pre-populate job_id in application form + add_filter( 'frm_get_default_value', array( __CLASS__, 'prepopulate_application_job_id' ), 10, 3 ); } /** @@ -1425,4 +1428,46 @@ class DDHH_JM_Formidable { FrmField::create( $field ); } } + + /** + * Pre-populate job_id field in application form + * + * @param mixed $default_value The default value. + * @param object $field The field object. + * @param bool $dynamic_default Whether to use dynamic default. + * @return mixed The modified default value. + */ + public static function prepopulate_application_job_id( $default_value, $field, $dynamic_default ) { + // Only process for the job application form + if ( absint( $field->form_id ) !== self::get_job_application_form_id() ) { + return $default_value; + } + + // Only process the job_id field + if ( 'job_id' !== $field->field_key ) { + return $default_value; + } + + // Check for job_id in shortcode attributes (passed from template) + // Formidable stores shortcode attributes in a global variable + global $frm_vars; + if ( isset( $frm_vars['job_id'] ) ) { + return absint( $frm_vars['job_id'] ); + } + + // Fallback: Check URL parameter + if ( isset( $_GET['job_id'] ) ) { + return absint( $_GET['job_id'] ); + } + + // Fallback: Try to get from current post if we're on a single job page + if ( is_singular( 'job_offer' ) ) { + global $post; + if ( $post && 'job_offer' === $post->post_type ) { + return absint( $post->ID ); + } + } + + return $default_value; + } } diff --git a/includes/class-notifications.php b/includes/class-notifications.php index c235d55..93bd726 100644 --- a/includes/class-notifications.php +++ b/includes/class-notifications.php @@ -339,7 +339,7 @@ class DDHH_JM_Notifications { public static function send_provider_application_notification( $entry_id, $form_id ) { // Only process job application form submissions $application_form_id = DDHH_JM_Formidable::get_job_application_form_id(); - if ( $form_id !== $application_form_id ) { + if ( $form_id != $application_form_id ) { return; } @@ -372,6 +372,7 @@ class DDHH_JM_Notifications { $applicant_message = sanitize_textarea_field( $value ); break; case 'job_id': + case 'job_id2': $job_id = absint( $value ); break; } diff --git a/includes/class-template.php b/includes/class-template.php index d1a2ffa..c668195 100644 --- a/includes/class-template.php +++ b/includes/class-template.php @@ -90,8 +90,30 @@ class DDHH_JM_Template {
-

Jetzt bewerben

-

Interessiert? Kontaktieren Sie uns unter:

+

Interesse?

+ +
+ + + @@ -130,11 +152,171 @@ class DDHH_JM_Template { padding: 1.5em; border-left: 4px solid #0073aa; border-radius: 4px; + text-align: center; } .ddhh-job-offer-details .job-application-section h3 { margin-top: 0; } + .ddhh-job-offer-details .ddhh-contact-button { + background: #0073aa; + color: white; + border: none; + padding: 12px 30px; + font-size: 16px; + border-radius: 4px; + cursor: pointer; + transition: background 0.3s ease; + } + .ddhh-job-offer-details .ddhh-contact-button:hover { + background: #005a87; + } + + /* Modal Styles */ + .ddhh-modal { + position: fixed; + z-index: 9999; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.6); + } + .ddhh-modal-content { + background-color: #fefefe; + margin: 5% auto; + padding: 30px; + border: 1px solid #888; + border-radius: 8px; + width: 90%; + max-width: 600px; + position: relative; + box-shadow: 0 4px 6px rgba(0,0,0,0.1); + } + .ddhh-modal-close { + color: #aaa; + float: right; + font-size: 32px; + font-weight: bold; + line-height: 20px; + cursor: pointer; + transition: color 0.3s ease; + } + .ddhh-modal-close:hover, + .ddhh-modal-close:focus { + color: #000; + } + .ddhh-modal-body { + margin-top: 20px; + } + .ddhh-modal h3 { + margin-top: 0; + color: #333; + } + +