feat(05-02): create job application form in Formidable class

Add create_job_application_form() method with 4 fields:
- applicant_name (text, required)
- applicant_email (email, required, pre-filled for logged-in users)
- applicant_message (textarea, required)
- job_id (hidden)

Form title: "Jetzt bewerben"
Submit button: "Bewerbung absenden"
Success message: "Ihre Bewerbung wurde versendet. Der Anbieter wird sich bei Ihnen melden."

Added get_job_application_form_id() helper method
Registered form creation in setup_registration_hooks()

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-14 20:29:39 +09:00
parent c8b911bd6b
commit 061a41033d

View File

@@ -41,6 +41,13 @@ class DDHH_JM_Formidable {
*/
private static $job_deactivation_form_id = null;
/**
* Form ID for job application
*
* @var int|null
*/
private static $job_application_form_id = null;
/**
* Get the registration form ID
*
@@ -121,6 +128,26 @@ class DDHH_JM_Formidable {
return null;
}
/**
* Get the job application form ID
*
* @return int|null Form ID or null if not found
*/
public static function get_job_application_form_id() {
if ( null !== self::$job_application_form_id ) {
return self::$job_application_form_id;
}
// Look up form by key
$form = FrmForm::getOne( 'job_application' );
if ( $form ) {
self::$job_application_form_id = $form->id;
return self::$job_application_form_id;
}
return null;
}
/**
* Setup registration hooks
*/
@@ -130,6 +157,7 @@ class DDHH_JM_Formidable {
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__, 'create_job_deactivation_form' ), 11 );
add_action( 'init', array( __CLASS__, 'create_job_application_form' ), 11 );
// Hook into Formidable form submission
add_action( 'frm_after_create_entry', array( __CLASS__, 'handle_registration_submission' ), 30, 2 );
@@ -826,4 +854,90 @@ class DDHH_JM_Formidable {
return $errors;
}
/**
* Create the job application form programmatically if it doesn't exist
*/
public static function create_job_application_form() {
// Check if Formidable is active
if ( ! class_exists( 'FrmForm' ) ) {
return;
}
// Check if form already exists
$existing_form = FrmForm::getOne( 'job_application' );
if ( $existing_form ) {
self::$job_application_form_id = $existing_form->id;
return;
}
// Create form
$form_values = array(
'name' => 'Jetzt bewerben',
'form_key' => 'job_application',
'description' => '',
'status' => 'published',
'options' => array(
'submit_value' => 'Bewerbung absenden',
'success_msg' => 'Ihre Bewerbung wurde versendet. Der Anbieter wird sich bei Ihnen melden.',
),
);
$form_id = FrmForm::create( $form_values );
if ( ! $form_id ) {
return;
}
self::$job_application_form_id = $form_id;
// Get current user email if logged in
$current_user = wp_get_current_user();
$default_email = '';
if ( $current_user && $current_user->ID ) {
$default_email = $current_user->user_email;
}
// Create form fields
$fields_data = array(
array(
'name' => 'Name',
'field_key' => 'applicant_name',
'type' => 'text',
'required' => '1',
'form_id' => $form_id,
'field_order' => 1,
),
array(
'name' => 'E-Mail',
'field_key' => 'applicant_email',
'type' => 'email',
'required' => '1',
'form_id' => $form_id,
'field_order' => 2,
'default_value' => $default_email,
),
array(
'name' => 'Nachricht',
'description' => 'Warum interessieren Sie sich für diese Stelle?',
'field_key' => 'applicant_message',
'type' => 'textarea',
'required' => '1',
'form_id' => $form_id,
'field_order' => 3,
),
array(
'name' => 'Job ID',
'field_key' => 'job_id',
'type' => 'hidden',
'required' => '0',
'form_id' => $form_id,
'field_order' => 4,
),
);
foreach ( $fields_data as $field ) {
FrmField::create( $field );
}
}
}