Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using Validation Rules (not from POST)
  • The validation rules can be applied to POST data when a form is submitted. But is there a simple way to use the validation rules against non-POST data, for example to check whether a string contains a valid email address? -- JJ
  • Correct. The production documentation is always linked to the current official release. Which in turn can be found in the master branch of that release number. The develop branch contains the current development version. Once that is getting ready for release, we announce a feature-freeze, and release the first RC. After that, we only accept bugfixes (no API changes) for that branch, until it is promoted to official release. Then, the cycle starts again. We do the same for every repository, including docs. The release mechanism is based on git-flow (http://nvie.com/posts/a-successful-git-branching-model/).
  • I have the answer, after looking through the code. This will apply the validation rules against POST data:
    if ($val->run()) ...
    

    This will run the same rules against an array of key/value pairs, where the keys are the mapped to the validation rules:
    if ($val->run( array($my_validation_rule => $my_value_to_validate) )) ...
    

    e.g. to validate $email as a valid email:
    $val = Validation::factory();
    $val->add('email')->add_rule('valid_email');
    if ($val->run(array('email'=>$email)))
    {
        echo " '$email' is a valid email or is empty ";
    }
    else
    {
        echo " '$email' is NOT a valid email ";
    }
    
  • Jason Judge wrote on Thursday 10th of November 2011:
    The validation rules can be applied to POST data when a form is submitted. But is there a simple way to use the validation rules against non-POST data, for example to check whether a string contains a valid email address? -- JJ
    Hello, your posted code
    $val = Validation::factory();
    $val->add('email')->add_rule('valid_email');
    if ($val->run(array('email'=>$email)))
    {
        echo " '$email' is a valid email or is empty ";
    }
    else
    {
        echo " '$email' is NOT a valid email ";
    }
    

    should work fine. as $val->run() checks post by default nothing is passed as the first argument
  • In addition, this is how you would validate a GET method form:
    $val->run(Input::get(NULL))
    

    Note that NULL has to be passed in, as there is no default value set for the get method parameter.
  • Don't know which version you're looking at, but 1.1 returns the entire $_GET array when you use Input::get().
  • Harro Verton wrote on Sunday 13th of November 2011:
    Don't know which version you're looking at, but 1.1 returns the entire $_GET array when you use Input::get().

    Yes, you are right, I just tried it. Maybe I was just taking the documentation too literally - http://fuelphp.com/docs/classes/input.html - it says the first parameter to get() is required, but it is actually optional, as you point out. -- Jason
  • Please note that the official docs are for the official release, as of now that is 1.0.1. If you're using the develop branch code, you should look at http://fuelphp.com/dev-docs.
  • Harro Verton wrote on Monday 14th of November 2011:
    Please note that the official docs are for the official release, as of now that is 1.0.1. If you're using the develop branch code, you should look at http://fuelphp.com/dev-docs.

    The dev branch is probably a little cutting edge for me ATM, but I am running from the 1.1 RC. I'll check both sets of documentation, as it is not clear which set is being updated - both mostly overlap, but both have missing chunks labelled "to be completed". Maybe the official docs have been abandoned in favour of updating the dev docs. Maybe both are being maintained in parallel, albeit slowly - like I say, it is not entirely clear.
  • 1.1 is in feature freeze as of 1.1 RC1. So all modifications are bugfixes, and for that reason 1.1/develop should be more stable than RC1. But as to docs it doesn't matter. /docs is for the current offficial release (1.0.1), and you're on a 1.1 branch, and should use /dev-docs. As soon as we officially release 1.1, the contents of /dev-docs will be moved to /docs.
  • Okay, so documentation is frozen with a release, so the 1.0 documentation will not be completed, but will be replaced with a new documentation set when the next version comes out of RC. I'll keep myself updated with the dev branch in the meantime - thanks for the tip. So the dev branch presumably goes through periods of stability and more rapid development, depending on whether there is an RC out or not. Still getting to grips with the way the product works. -- Jason

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion