• A new version of Full Calendar is now available.

    See the details here

PHP validation

  • Views Views: 24,559
  • Last updated Last updated:

Navigation

      Access element (+)
      Birthday element
      Button element
      Calculation element
      Captcha element
      Checkbox element
      Colour Picker element
      Count element (+)
      Database join element
      Date element
      Digg element
      Display text element
      Dropdown element
      Facebook Like element
      Field element
      File Upload element
      Folder element
      Google Map element
      Image element
         Image databese join
      Internal id element
      IP element
      J!Date element
      Kaltura element
      Link element
      Notes element
      OpenStreetMap element
      Picklist element
      Radio Button element
      Rating element
      Sequence element
      Slider element
      Tags element
      Textarea element
      Thumbs element
      Time element
      Timer element
      Timestamp element
      Total element
      User element
      User group element
      Video element
      View level element
      YesNo element
      Youtube element
      Akismet validation
      Is Email validation
      Is Not validation
      Is Numeric validation
      Not empty validation
      PHP validation
      Rsa id
  • Settings​


    php.png


    A customizable Validation rule. Runs PHP code to test for Validation success or failure

    • Error message - The message to display next to the element if the Validation fails. This text should explain why the Validation failed and what steps the user should take to remedy the error.
    • Condition - A PHP expression which if returns false, means that the Validation is not run.
    • PHP -PHP code to run.
      • The element's submitted value is found in the variable $data.
      • Other element values can be found in $_REQUEST (use JFactory::getApplication()->input->get() to access).
      • If the code returns TRUE then the Validation is successful,
      • If it returns FALSE then the Validation fails.
      • You can also return a string which can be used if the 'Match or replace' option is set to 'replace'
    • Match or Replace - If set to match then the Validation behaves as normal and on Validation failure returns you to the form showing the error message. If set to 'replace' then the submitted value is replaced with the data returned from the 'PHP code' script
    • Tip text - additonal informational text which is displayed as a tip when the user hovers over the element's label. This can provide specific information about the Validation, enabling the user to correctly fill in the field.
    Placeholders may be used in the PHP code or condition fields.

    Examples​

    Ensure a date Elements value (stored in the value $data) is greater than another's whose full element name is 'tablename___elementname':
    PHP:
    $app = JFactory::getApplication();
    $f = $app->input->get('tablename___elementname', 'default value', 'string'); //'string' = filter e.g. 'INT','STRING'
    $f = JFactory::getDate($f)->toUnix();
    $data = JFactory::getDate($data)->toUnix();
    return $data > $f;

    Set a custom error message​


    As of 14/08/2013 (fabrik 3.0.x and 3.1) you can do this....
    PHP:

    $this->setMessage('oh dear you can not do that!');

    In Fabrik 4 do
    $thisValidation->setMessage('oh dear you can not do that!');

    repeat group data​


    When your element is in a repeating group, then the placeholder contains the value for the current repeat group's values.

    For example you have a form with a repeat group 'regions' and within that group you have a field 'regions___label'. Lets say the form is submitted with two repeat Groups, in the first repeat group the label is 'Warwickshire' and in the second group the label is 'Yorkshire'.

    If you add the following code as your validation:

    PHP:

    echo "<pre>";print_r($data);
    exit;

    then upon form submission you will see an array :

    Code:

    Array
    (
    [0] => Warwickshire
    [1] => Yorkshire
    )

    If you replace the validation PHP with

    PHP:

    echo '{regions___dropdown}';
    exit;


    the output will be

    Code:

    Warwickshire

    As the first validation runs and our exit will stop the code. If there was no exit the validation would be run for each repeat group, with the successive values 'Warwickshire' and 'Yorkshire' being used
Back
Top