Can I use placeholders inside MODX Revolution FormIt parameters?

320 Views Asked by At

I try to learn MODX FormIt component usage (MODX revolution v.2.7.0, FormIt v. 4.1.1). Now I try to set validation rules for form field, such as "required, only numbers, greater than", meanwhile I want to use placeholder for minimal value. I call FormIt like this:

[[!FormIt?  
  &hooks=`openSession`
  &redirectTo=`1`
  &placeholderPrefix=``
  &validate=`my_field:required:isNumber:minValue=`[[!+my_min_value]]``
]]

but I can input any number in 'my_field' field. If I use number for minValue instead of placeholder, all works fine. Placeholder is successfully resolving into number in the form below, too. When I am wrong?

1

There are 1 best solutions below

2
On

IIRC, you cannot use placeholders in the parameters.

Although, you should try with the following code, in case it is now supported in latest versions:

[[!FormIt?  
  &hooks=`openSession`
  &redirectTo=`1`
  &placeholderPrefix=``
  &validate=`my_field:required:isNumber:minValue=^[[!+my_min_value]]^`
]]

OR

You could use custom validator, in which you should be able to use getPlaceholder to read your placeholder.

For more details on why use ^ instead of back-ticks, please see https://docs.modx.com/extras/revo/formit/formit.validators