• 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: Custom Validation RUles

Custom Validation RUles 10 years 7 months ago #28756

Hi all!
I would like to create a validation form. You can see an example in this page.
www.ptqualityfurs.com/index.php/en/product-verification

The customer will submit a code number. The form will check its validity and then return a true or false message.
The administrator must have the ability to easily write all the RIGHT code numbers in a list and the form when executed will make the validation by checking this list.
Is it possible to do it with RS Form and how can I do it?
Paschalis
The administrator has disabled public write access.

Custom Validation RUles 10 years 7 months ago #28763

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
This scenario can be achieved using PHP Scripts called on form process or adding your own validation rule.

http://www.rsjoomla.com/support/documentation/view-article/75-custom-validation-rules.html

Using the first method, you will have to create a PHP script that will grab the submitted value and search it in an array. If it doesn't find a match, it should invalidate the field

http://www.rsjoomla.com/support/documentation/view-article/602-php-scripts.html

A similar example can be found in this forum post :

http://www.rsjoomla.com/forum/37-rsform-pro/24385-change-validation-rule-by-dropdown.html#28429
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

Custom Validation RUles 10 years 7 months ago #28854

OK Cosmin
I tried this (custom validation rules) but it can only check one code word or number every time, eg "test".
I need to search this number from a phpmyadmin table and if the number is listed then it's TRUE, if it's not then it's FALSE. How can I do ut?
Paschalis
The administrator has disabled public write access.

Custom Validation RUles 10 years 7 months ago #28864

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
An example on custom validation rule for a code can be found below:
public static function registrationCode($value, $extra = null, $data = null) {
 
	$validCodes = array('AAA', 'BBB', 'CCC');   // Define the codes in the array here, Please use the correct syntax!
	$db = JFactory::getDBO();
	$db->setQuery("SELECT COUNT(`FieldValue`) FROM #__rsform_submission_values WHERE `FieldValue`='".$value."'");
	$tmp = $db->loadResult();	
	foreach ($validCodes as $code) {
		if (strtolower($value) == strtolower($code) && $tmp == 0) {
		return true;
		}
	}
		// When all of the above fails, the supplied code is incorrect, so we have to return false.
		return false;
}	
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 7 months ago by cosmin.cristea.
The administrator has disabled public write access.

Custom Validation RUles 10 years 7 months ago #28866

Hi Cosmin, this is much better, but again, if I understand well, there are only three codes (AAA, BBB, CCC)
Please correct me if I'm wrong.
*** But I must enter at least a thousand codes. ***
The only way is to read those codes from a list of numbers entered previously on a table field in the database.

I don't understand the line:
$db->setQuery("SELECT COUNT(`FieldValue`) FROM #__rsform_submission_values WHERE `FieldValue`='".$value."'");

Is this reading codes from a table? Or writing them?
Paschalis
Last Edit: 10 years 7 months ago by karakoutas.
The administrator has disabled public write access.

Custom Validation RUles 10 years 7 months ago #28891

OK I found it.
G
The administrator has disabled public write access.

Custom Validation RUles 10 years 5 months ago #29447

Hi Karakoutas,

You wrote:

*** But I must enter at least a thousand codes. ***
The only way is to read those codes from a list of numbers entered previously on a table field in the database.

I don't understand the line:

$db->setQuery("SELECT COUNT(`FieldValue`) FROM #__rsform_submission_values WHERE `FieldValue`='".$value."'");

Is this reading codes from a table? Or writing them?

>>Could you please tell me how did you resolve it? Is this reading from a table?

Best regards,
The administrator has disabled public write access.

Custom Validation RUles 10 years 5 months ago #29506

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
That particular query, counts how many times that specific values has been entered. The result of the query is used to invalidate the form field if it finds a value different than 0, here:
	if (strtolower($value) == strtolower($code) && $tmp == 0) {
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 5 months ago by cosmin.cristea.
The administrator has disabled public write access.

Custom Validation RUles 10 years 4 months ago #29822

  • mojtabapordel
  • mojtabapordel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 6
Hi
I didn't understand this line:
$validCodes = array('AAA', 'BBB', 'CCC'); // Define the codes in the array here, Please use the correct syntax!
I made a table in phpmyadmin called : __karshenasi_codes
This table has one column called "codes" and in this column I wrote 1000 codes.
Now how can I change that validation rule to check these 1000 codes in DB and prevent the form submission if user enter the wrong code?
Thank you
The administrator has disabled public write access.

Custom Validation RUles 10 years 4 months ago #29826

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Retrieving an array of codes can be simply achieved by loading that specific column, example:
$db->setQuery("SELECT `codes` FROM `# __karshenasi_codes`");
$validCodes = $db->loadColumn(); // this array holds all your codes, you can crosscheck the values as per the rest of the example

PS: You will have to remove the following line from the example:
$validCodes = array('AAA', 'BBB', 'CCC'); // Define the codes in the array here, Please use the correct syntax!
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: mojtabapordel, rflexii
  • 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!