• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Form with limited product availebility

Form with limited product availebility 5 years 5 months ago #39531

hello,

I have a form where you can buy a entry to a event that has diffrent classes.
Example:

class 1: 10 places available
class 2: 15 places available
class 3: 10 places available

How can i put this in a form so attendees can see how many places are free in each class and submit a entry in to a free class?

Thanks

Roy
The administrator has disabled public write access.

Form with limited product availebility 5 years 5 months ago #39540

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
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.
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.
The following user(s) said Thank You: velthof.roy

Form with limited product availebility 5 years 5 months ago #39552

OK, will try this.

Thanks!
The administrator has disabled public write access.

Form with limited product availebility 3 months 3 weeks ago #43799

  • c.poffet
  • c.poffet's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
I'm looking for the same function without the shop function. It's for registering volunteers for tasks. As the number of volunteers per task is limited, I'd like the task to be more available.
For example
Tournament management
task 1: Technical (5 places available)
task 2: Security (10 places available)
task 3: Gastronomy (20 places available)
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!