How to decrease numbers 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.

This is a variation to the existing Formidable Forms‘ Knowledge Base article Decrease an available count in another 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

In order to decrease a number in another form, you will need a second form.

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

The form 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 reaches the X limit.

Use the function below to make the number of seats decrease by a variable amount (instead of a fixed amount like the KB article shows):

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 ) );

We’ve referenced various Fields in the snippet above. For more information, see below:
95 is the ID of the Dynamic Dropdown field in your booking form.
96 is the ID of the number of places that are being booked.
91 is the ID of the number of places in Form 1
9 is the ID of Form 2

And Thats It!

Check out the other demos and tutorials in our blog using the links below.

Let's Get Started

If you’re ready to get started with your next project click on the button below to try the Project Planner


You may also like…

Form TimerDemosFormidableTutorials
28 Feb 2019

Form Timer: Formidable Forms

Formidable Forms: Stopwatch / Form Timer - This guide details how to create a form timer / stopwatch that can…
Invoicing SystemFormidableTutorials
26 Mar 2019

Create an Invoicing system: Formidable Forms

Create an Invoicing system: Formidable Forms In this guide you'll learn how to use Formidable Forms Pro to create an…
25 Jun 2018

Formidable Forms – Radio & Checkbox Demos

Radio Button & Checkbox Styles These styles have been created using JS, CSS and Formidable Forms. Read the full tutorial…