The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Count of seats in classroom

Labels

This Discussion is public

Notifications

I have a registration-form an a classes-form. The classes-form has different classes and defines, how many seats are available. The registration-form implements the classes-form and should decount by every registration the seats in the class-table, so I know, when the class is fully booked. For this decount I became some years ago a code-snipped.

Now I have a problem in my registration form. It worked last year, but this year it always copies the max amount of seats from the class-form to the reservation-form and the amount of available seats in the class-form stays the same.

Here the Code, that worked last year perfect:

add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
  // Referat 1
  if($form_id == 2){                           //2 is the ID of my registration-form
    global $wpdb, $frmdb;
    $reward_id = $_POST['item_meta'][130];     //130 is the ID of your drop-down data from entries field in your reservations-form
    $seat_count_field = 127;                   //127 is the ID of the available seats field in the class-form
    $available = FrmEntryMeta::get_entry_meta_by_field($reward_id, $seat_count_field, true);
    $wpdb->update($frmdb->entry_metas, array('meta_value' => ((int)$available-1)), array('item_id' => $reward_id, 'field_id' => $seat_count_field));
  }

Idea:
Decrease an available count in another form
This example assumes you have two forms set up: one for the event and one for reservations. The event form will include a field for the number of available openings. The reservation form will include a data from entries field to list all the events. This function will drop the number of available openings for an event when it is selected.

I’m sorry but I’m not programmer enough to find the problem myself.
Many thanks for your great help.

Cheers,
Stephan

Found it myself in a hook of the formidable-Page: https://formidableforms.com/knowledgebase/frm_after_create_entry/
Decrease an available count in another form#
add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
if($form_id == 5){ //change 5 to the ID of your reservations form
global $wpdb;
$reward_ids = $_POST['item_meta'][25]; //change 25 to the ID of your Dynamic dropdown field in your reservations form
$seat_count_field = 15; //change 15 to the ID of the available seats field in the event form
foreach ( (array) $reward_ids as $reward_id ) {
$available = FrmEntryMeta::get_entry_meta_by_field( $reward_id, $seat_count_field, true );
$wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => ( (int) $available-1 ) ), array( 'item_id' => $reward_id, 'field_id' => $seat_count_field ) );
}
}
}

Works fine, when globally executed.

Discussion closed.