fix: repair job_type dropdown options and remove job_logo from forms

The job_type select field had empty options because Formidable stores
them in a top-level `options` key, not nested inside `field_options`.
The job_logo field is removed from both submission and edit forms since
the logo is managed per-provider on the dashboard.

Includes a one-time repair migration that fixes existing fields in the
database (updates job_type options, deletes job_logo fields).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 13:37:20 +09:00
parent 346ef5097b
commit b7c6bb79e7
2 changed files with 54 additions and 65 deletions

View File

@@ -156,6 +156,7 @@ class DDHH_JM_Formidable {
add_action( 'init', array( __CLASS__, 'create_registration_form' ), 11 );
add_action( 'init', array( __CLASS__, 'create_job_submission_form' ), 11 );
add_action( 'init', array( __CLASS__, 'create_job_edit_form' ), 11 );
add_action( 'init', array( __CLASS__, 'repair_job_form_fields' ), 12 );
add_action( 'init', array( __CLASS__, 'create_job_deactivation_form' ), 11 );
add_action( 'init', array( __CLASS__, 'create_job_application_form' ), 11 );
@@ -808,19 +809,13 @@ class DDHH_JM_Formidable {
'field_order' => 3,
),
array(
'name' => 'Art',
'field_key' => 'job_type',
'type' => 'select',
'required' => '1',
'form_id' => $form_id,
'field_order' => 4,
'field_options' => array(
'options' => array(
'Vollzeit' => 'Vollzeit',
'Teilzeit' => 'Teilzeit',
'Ehrenamt' => 'Ehrenamt',
),
),
'name' => 'Art',
'field_key' => 'job_type',
'type' => 'select',
'required' => '1',
'form_id' => $form_id,
'field_order' => 4,
'options' => array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' ),
),
array(
'name' => 'Bewerbungsfrist',
@@ -841,19 +836,6 @@ class DDHH_JM_Formidable {
'form_id' => $form_id,
'field_order' => 6,
),
array(
'name' => 'Logo',
'field_key' => 'job_logo',
'type' => 'file',
'required' => '0',
'form_id' => $form_id,
'field_order' => 7,
'field_options' => array(
'restrict' => '1',
'allowed_types' => 'image/jpeg,image/png',
'max_size' => '2',
),
),
);
// Store field IDs for form action mapping
@@ -879,7 +861,6 @@ class DDHH_JM_Formidable {
array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ),
array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ),
array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ),
array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ),
);
$action_control->save_settings( $new_action );
}
@@ -950,19 +931,13 @@ class DDHH_JM_Formidable {
'field_order' => 3,
),
array(
'name' => 'Art',
'field_key' => 'job_type',
'type' => 'select',
'required' => '1',
'form_id' => $form_id,
'field_order' => 4,
'field_options' => array(
'options' => array(
'Vollzeit' => 'Vollzeit',
'Teilzeit' => 'Teilzeit',
'Ehrenamt' => 'Ehrenamt',
),
),
'name' => 'Art',
'field_key' => 'job_type',
'type' => 'select',
'required' => '1',
'form_id' => $form_id,
'field_order' => 4,
'options' => array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' ),
),
array(
'name' => 'Bewerbungsfrist',
@@ -983,19 +958,6 @@ class DDHH_JM_Formidable {
'form_id' => $form_id,
'field_order' => 6,
),
array(
'name' => 'Logo',
'field_key' => 'job_logo',
'type' => 'file',
'required' => '0',
'form_id' => $form_id,
'field_order' => 7,
'field_options' => array(
'restrict' => '1',
'allowed_types' => 'image/jpeg,image/png',
'max_size' => '2',
),
),
);
// Store field IDs for form action mapping
@@ -1021,12 +983,50 @@ class DDHH_JM_Formidable {
array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ),
array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ),
array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ),
array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ),
);
$action_control->save_settings( $new_action );
}
}
/**
* Repair existing job form fields in the database.
*
* Fixes the job_type select options and removes the job_logo field
* from both the submission and edit forms. Runs once and stores a
* version flag in wp_options to avoid re-running.
*/
public static function repair_job_form_fields() {
if ( ! class_exists( 'FrmField' ) ) {
return;
}
$repair_version = '1';
if ( get_option( 'ddhh_jm_form_repair_version' ) === $repair_version ) {
return;
}
// Fix job_type options on both forms.
$correct_options = array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' );
foreach ( array( 'job_type', 'job_type2' ) as $key ) {
$field = FrmField::getOne( $key );
if ( $field ) {
FrmField::update( $field->id, array(
'options' => serialize( $correct_options ),
) );
}
}
// Remove job_logo fields from both forms.
foreach ( array( 'job_logo', 'job_logo2' ) as $key ) {
$field = FrmField::getOne( $key );
if ( $field ) {
FrmField::destroy( $field->id );
}
}
update_option( 'ddhh_jm_form_repair_version', $repair_version );
}
/**
* Pre-populate edit form fields with existing post data
*