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 preparing for archive only
 
(One intermediate revision by the same user not shown)
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}}
 
 


===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>
 
</span>
{{SeeAlso:JModelForm/validate}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=validate
  category=validate
  category=JModelForm
  category=JModelForm
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 01:55, 25 March 2017

Description

Method to validate the form data.



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;
}



Examples

Code Examples