How to decrease numbers in another form

This is a variation to the existing KB article Decrease an available count in another form.

This article will guide you on how to use a variable field in one form to decrease a number in another form. The example we will cover will include 2 forms, an Event Management Form – Admin Only and an Event Booking Form.

Here’s the set-up:

Form 1: Event Management Form – Admin Only

This form is used for adding new events and contains the following fields (although you can add any fields you like):

  • Event Name
  • Event Date
  • Number of places available
  • Event Description

Form 2: Event Booking Form

This form is your event booking form and uses a Dynamic Dropdown field to look at Form 1 > Event Date and display the dates available.

It also uses a 2nd Dynamic List field to display the number of places still available and a hidden field to capture this number which can then be used elsewhere in the form to control conditional logic for your form elements if the number of places gets below X.

To make the number of seats decrease by a variable amount (instead of a fixed amount like the KB article shows) use this function:


add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
  if($form_id == 9){ //change 9 to the ID of your reservations form
    global $wpdb;
    $reward_ids = $_POST['item_meta'][95]; //change 95 to the ID of your Dynamic dropdown field in your reservations form
$booking_num = $_POST['item_meta'][96]; //change 96 to the ID of your booking places field in your reservations form
    $seat_count_field = 91; //change 91 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, $booking_num, true );
        $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => ( (int) $available-$booking_num ) ), array( 'item_id' => $reward_id, 'field_id' => $seat_count_field ) );

    }
  }
}

Field 95 is the ID of the Dynamic Dropdown field in your booking form.
Field 96 is the ID of the number of places that are being booked.
Field 91 is the ID of the number of places in Form 1
9 is the ID of Form 2

Still have questions?

Still have questions or not sure where to start? Use our quick contact to ask us a question.

Start Planning

If you’re ready to get started click here to complete our Project Planner.

You may also like…

FormidableTutorials
26 Mar 2019

Formidable Forms: File Upload Folder

Formidable Forms: Changing the File Upload Folder The Problem: You may want to change the folder that files will be…
FormidableTutorials
26 Mar 2019

Formidable Forms: Create an Invoicing system

Formidable Forms: Create an Invoicing system Here’s a guide on how to use Formidable Pro to create an invoicing system…
FormidableTutorials
26 Mar 2019

Share a form entry between users

Formidable Forms: Create a shared entry & view The Problem In some cases you may need to build a form…