Hello,
Although there are no such particular booking features at this moment for RSForm!Pro, due to its flexible nature you can try a custom approach through its scripting areas.
Before starting off, if you have
RSEvents!Pro as well, you can use
their integration plugin, or even RSEvents!Pro on its own, and setup the seats availability via your RSEvents!Pro event without any custom scripting whatsoever.
If you don't, then you can try similar steps (I'm assuming you're using the
RSForm!Pro Payment Package plugin and this refers to a
Multi Product type filed set as a
single selection dropdown):
- edit your Multi Product field and place the following code (
including the
//<code> and
//</code> tags) within its "
Items" area (replace accordingly):
//<code>
//replace the ID number, in this case 5, with your exact form ID.
$formId = 5;
//replace the field name, in this case myMultiProduct, with the exact name you've given to your Multi Product element (case sensitive).
$productFieldName = 'myMultiProduct';
//this is the string used in the frontend based on your example, you can have it replaced as needed:
$string = "places available";
//here, replace only the values after the "=>" symbols, like 100, 10 or class1 naming. The price is added like this with no currency.
$items = [
['price'=>'100', 'spots'=>'10', 'name'=>'class1'],
['price'=>'150', 'spots'=>'15', 'name'=>'class2'],
['price'=>'200', 'spots'=>'10', 'name'=>'class3']
];
$db = JFactory::getDBO();
$finalItems = array();
foreach($items as $item){
$db->setQuery("SELECT COUNT(`FieldValue`) FROM #__rsform_submission_values WHERE `formId`='".$formId."' AND `FieldName`='".$productFieldName."' AND `FieldValue` LIKE '".$item['name']."%'");
$itemSubmittedNumber = $db->loadResult();
$item['spots'] = intval($item['spots']) - intval($itemSubmittedNumber);
if($item['spots'] < 1){
$finalItems[] = $item['price']."|".$item['name'].": ".$item['spots']." ".$string."[d]";
}else{
$finalItems[] = $item['price']."|".$item['name'].": ".$item['spots']." ".$string;
}
}
return implode("\n", $finalItems);
//</code>
The script will also disable the selection if all its items have been submitted and will display 0 places available.
- there may be cases when there's only 1 spot left on a selection and multiple users try to submit the form at roughly the same time with that particular last selection (which would normally account for one single user). The following script should prevent this from happening and will invalidate the Multi Product element if the last item was already given. This is added while editing the form > Properties >
PHP Scripts > Scripts Called On Form Process area (the middle one):
//this script is slightly similar though you'll still have to replace the followings.
//replace the field name, in this case myMultiProduct, with the exact name you've given to your Multi Product element (case sensitive).
$productFieldName = 'myMultiProduct';
//this is the custom validation message that will show for your field if a user tries to submit the form with a sold out item:
$customValidationMessage = 'There are no more spots available for this selection. Refresh the page to update form data.';
//replace the values here to coincide as you did on the first initial script; the price is no longer included since it's not needed.
$items = [
['spots'=>'10', 'name'=>'class1'],
['spots'=>'15', 'name'=>'class2'],
['spots'=>'10', 'name'=>'class3']
];
$db = JFactory::getDBO();
$finalItems = array();
foreach($items as $item){
if($item['name'] == explode(":", $_POST['form'][$productFieldName][0])[0]){
$db->setQuery("SELECT COUNT(`FieldValue`) FROM #__rsform_submission_values WHERE `formId`='".$formId."' AND `FieldName`='".$productFieldName."' AND `FieldValue` LIKE '".$item['name']."%'");
$itemSubmittedNumber = $db->loadResult();
$item['spots'] = intval($item['spots']) - intval($itemSubmittedNumber);
if($item['spots'] < 1){
$myFieldId = RSFormProHelper::getComponentId($productFieldName);
$properties = &RSFormProHelper::getComponentProperties($myFieldId);
$properties['VALIDATIONMESSAGE'] = $customValidationMessage;
$invalid[] = $myFieldId;
}
}
}
If you take this approach, I would recommend that you thoroughly test the form to ensure this is indeed applied as intended. If after your tests, you want to "reset" available spots, either increase the spot numbers (in both script instances) or simply delete your testing submissions.