Tag Archives: FuelPHP

FuelPHP Input arrays validation

After pulling some hair and digging a lot in FuelPHP core I finally discovered a litle hack that allows validation of input arrays and its re-population using FuelPHP Validation Class.

Here’s how I did it:

View simplified for the sake of the example:

<?php echo \Form::label("Price", "options[0][price]"); ?>
<?php echo \Form::input("options[0][price]", \Validation::instance()->input("options.0.price"); ?>

<?php echo \Form::label("Name", "options[0][name]"); ?>
<?php echo \Form::input("options[0][name]", \Validation::instance()->input("options.0.name"); ?>

<?php echo \Form::label("Price", "options[1][price]"); ?>
<?php echo \Form::input("options[1][price]", \Validation::instance()->input("options.1.price"); ?>

<?php echo \Form::label("Name", "options[1][name]"); ?>
<?php echo \Form::input("options[1][name]", \Validation::instance()->input("options.1.name"); ?>

Mind the options.0.name instead of options[0]name inside the Validation Input.

In my controller I did this:

$val = \Validation::factory();

if ( \Input::post("options") )
{
    $form_options = \Input::post("options");

    foreach ( $form_options as $form_id => $option )
    {
        $val->add("options.{$form_id}.price", "{$option["name"]} price")
                ->add_rule("required")
                ->add_rule("match_pattern", '/[0-9]*(\.|,)?[0-9]+/');

        $val->add("options.{$form_id}.name", "{$option["name"]} name")
                ->add_rule("required");

    }
}

 

And that’s it, this should validate the fields and repopulating them in case of errors. It’s a bit stupid that it only works like this.

FuelPHP should provide a friendlier way and a documented one to validate array input fields, it’s a common feature when dealing with dynamic built forms that have one-to-many objects in it.

 

Tested with FuelPHP 1.0.1

FuelPHP BreadCrumb Class/Library

Morning,

Just finish building a breadcrumb Class for FUELPHP.

This Class has persistent crumbs, meaning that visited crumbs will be saved in session.

GitHub link for FuelPHP-BreadCrumb

Read more »

FuelPHP version 1.0 is out

After 9 months in the oven here it is, the first oficial version of one of my personal favorities PHP frameworks.

FUEL is great for several reason, has a great  autoload system, DB class is greatly implemented and although I have not tested it ORM look sweet. The only thing I miss at the time I’m writing this is a official Email Class that I’m sure it will be out in a near future.

My advice is for you to try it, you’ll not be disappointed. Also if you need help the community in freenode channel #fuelphp is very friendly and helpful. Offcourse you always have the foruns.

The list of commits is huge, check if here: http://mjs.me/aB

Official blog post about it: http://mjs.me/aC

 

WEBSITE | GITHUB | DOWNLOAD v1.0

New version of URL Shortener mjs.me

MJS.ME

Shrink that huge URL

 

Just released a new version of http://mjs.me url shortener.

This is a complete rebuild using FuelPHP, it’s a great PHP framework and very fun to code with.

There still some missing features that I want to incorporate, I’ll release updates soon.

I have open source it, if you want to make changes feel free to check the code and send pull requests :)

DEMO | DOWNLOAD | SOURCE