• 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 - certain # of characters?

Custom Validation - certain # of characters? 10 years 6 months ago #29193

I'm looking to make a custom validation where the characters must be between 3 and 4 characters. I'm not the best coder, so what would be the best way of going about this.

Many thanks!
The administrator has disabled public write access.

Custom Validation - certain # of characters? 10 years 6 months ago #29199

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
You can use the following code in the PHP script called on form process:

Do not forget to change name_of_your_field with the actual field name from your form
$range = range(3, 4);
$fieldcheck = strlen($_POST['form']['name_of_your_field']);
 
if(!in_array($fieldcheck, $range)) {
 $invalid[] = RSFormProHelper::getComponentId("name_of_your_field");
}
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 6 months ago by cosmin.cristea.
The administrator has disabled public write access.

Custom Validation - certain # of characters? 10 years 6 months ago #29208

can I ask where form process is found?

under php scripts, I see three boxes:
"$formlayout"
"$_post"
and "$thankyoumessage"

sorry if I'm missing something obvious!
The administrator has disabled public write access.

Custom Validation - certain # of characters? 10 years 6 months ago #29210

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
The second one : "$_post" . I apologize, I should have given you this as well

www.rsjoomla.com/support/documentation/v...602-php-scripts.html
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 - certain # of characters? 10 years 6 months ago #29211

hmm I plugged it in and changed the name of the field, but it doesn't seem to be working. should I be changing the word "form" to the name of my form as well?
The administrator has disabled public write access.

Custom Validation - certain # of characters? 10 years 6 months ago #29212

aha! I see what happened!

It doesn't check the validation until I hit submit. is there a way for it to check the field on next as well?
The administrator has disabled public write access.

Custom Validation - certain # of characters? 10 years 6 months ago #29230

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Due to the fact that the action takes places on form process, it will not check for validation upon changing the page. In order to achieve that scenario, you will have to create a custom validation rule inside the dedicated php file :

\components\com_rsform\helpers\validation.php

The custom validation rule, for your exact scenario is this :
	public static function range($value) {
 
		$range = range(3, 4);
		$fieldcheck = strlen($value);
 
		if(in_array($fieldcheck, $range)) {
			return true;
		}
		else{
			return false;
		}
	}
PS: In order to work, you will have to edit that fieldname and set range as validation rule.

Try and let me know!
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 6 months ago by cosmin.cristea.
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!