API16

JModelForm/validate: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Method to validate the form data. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</n...
 
m clean up
Line 2: Line 2:
Method to validate the form data.
Method to validate the form data.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JModelForm/validate|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JModelForm/validate}}
 
{{subst:Description:JModelForm/validate}}


===Syntax===
===Syntax===
Line 63: Line 61:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JModelForm/validate|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JModelForm/validate}}
</span>
{{SeeAlso:JModelForm/validate}}


===Examples===
===Examples===

Revision as of 14:15, 24 March 2017

Description

Method to validate the form data.


{{subst:Description:JModelForm/validate}}

Syntax

validate($form, $data)
Parameter Name Default Value Description
$form $form The form to validate against.
$data $data The data to validate.

Returns

mixed Array of filtered data if valid, false otherwise.

Defined in

libraries/joomla/application/component/modelform.php

Importing

jimport( 'joomla.application.component.modelform' );

Source Body

function validate($form, $data)
{
        // Filter and validate the form data.
        $data   = $form->filter($data);
        $return = $form->validate($data);

        // Check for an error.
        if (JError::isError($return)) {
                $this->setError($return->getMessage());
                return false;
        }

        // Check the validation results.
        if ($return === false)
        {
                // Get the validation messages from the form.
                foreach ($form->getErrors() as $message) {
                        $this->setError($message);
                }

                return false;
        }

        return $data;
}


{{subst:SeeAlso:JModelForm/validate}}

Examples

<CodeExamplesForm />