Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
@Mirage

I'm not sure what you were intending to happen, but your row should be much simpler:
Code:
'coloroptions' => array (
    'label'=> 'Which colors do you like',
    'type' => 'checkbox',
    'name' => 'coloroptions[]',
    'list' => array (
        'green' => 'Green',
        'red' => 'Red',
        'yellow' => 'Yellow',
        'blue' => 'Blue'
    )
)

Which I tested, and works just fine. You can manually create checkboxes for each item, but that wouldn't be the result you wanted, I think.

It turns out that there is a different bug related to determining when to use append the square brackets ([]) and when not to. The code above will work for now, but you'll want to change it to this with the next update.
Code:
'coloroptions' => array (
    'label'=> 'Which colors do you like',
    'type' => 'checkbox',
    'list' => array (
        'green' => 'Green',
        'red' => 'Red',
        'yellow' => 'Yellow',
        'blue' => 'Blue'
    )
)

So you don't have to worry about modifying this, I've attached the updated htmlform extension.

HTMLForm also accepts a new option, defaultValue, which lets you set a default value for custom fields. It's a bit of a hack, because specifying value overrides the form-saved-with-errors method to re-fill in changed values.

[eluser]Mirage[/eluser]
Phil,

Your example is what I originally started with. But the problem (after figuring out the [] thing) is that I want to display the options like a multifield using a single row

[x] Green [x] Red [ ] Yellow [ ] Blue

rather than

[x] Green
[x] Red
[ ] Yellow
[ ] Blue

Thanks for the enhancements and the attached update.

Cheers,
-m

[eluser]OverZealous[/eluser]
[quote author="Mirage" date="1252464162"]I want to display the options like a multifield using a single row[/quote]

Ah, I understand now. I added an option, input_separator, that lets you override the default separator.

It is also used on radio sets, and when combining multiple input fields into one row.

I attached the updated version. Use it like this:
Code:
'coloroptions' => array (
    'label'=> 'Which colors do you like',
    'type' => 'checkbox',
    'input_separator' => ' ',
    'list' => array (
        'green' => 'Green',
        'red' => 'Red',
        'yellow' => 'Yellow',
        'blue' => 'Blue'
    )
)

You can place any valid HTML between each item.

UPDATE: I made a mistake, the new default value is going to be called default_value, instead of defaultValue, to be more consistent with DMZ naming. Please don't use it in the attached version.

[eluser]PoetaWD[/eluser]
@phil DeJarnett

I am glad I helped !

I am working a lot with those deep relationships ! The only bug I found was that...

I will post more feedbacks later !

See ya

[eluser]BrianDHall[/eluser]
Hey OverZealous, I think a found a bug in your _template.php file that is provided with DMZ.
Code:
// Uncomment and edit these two if the class has a model name that
    //   doesn't convert properly using the inflector_helper.
    // $model = 'template';
    // $table = 'templates';

However if I uncomment these I get a syntax error - should these instead be:
Code:
// Uncomment and edit these two if the class has a model name that
    //   doesn't convert properly using the inflector_helper.
    // var $model = 'template';
    // var $table = 'templates';

[eluser]OverZealous[/eluser]
[quote author="BrianDHall" date="1252456736"]I have a question - is there any method, magic or otherwise, that would allow setting a datamapper object property to a value with a function?
...
[/quote]

Hi Brian!

Before I answer in too much detail, why do you want this? I'm curious what the benefit of more redirection is. I'm not likely to add this to the core of DMZ, because I don't see the general benefit.

You can easily add this to a direct DataMapper extension class. The details are explained on that page.

You might write the code like this:
Code:
function __call($method, $arguments) {
    if(strpos('set_', $method) === 0) {
        $field = // substring out set_
        $this->{$field} = $arguments[0];
        return $this;
    }
    // REALLY important
    return parent::__call($method, $arguments);
}

I don't feel like looking up the PHP methods, but you get the idea. Make sure you use a triple-equals for that comparison above.

If you explicitly create a set_XXX method, the __call function will never be used, so you don't have to worry about that.

[eluser]OverZealous[/eluser]
[quote author="BrianDHall" date="1252466153"]Hey OverZealous, I think a found a bug in your _template.php file that is provided with DMZ.[/quote]

Yup, that was a bug. I fixed it. Thanks!

[eluser]BrianDHall[/eluser]
[quote author="OverZealous" date="1252466579"][quote author="BrianDHall" date="1252456736"]I have a question - is there any method, magic or otherwise, that would allow setting a datamapper object property to a value with a function?
...
[/quote]

Hi Brian!

Before I answer in too much detail, why do you want this? I'm curious what the benefit of more redirection is. I'm not likely to add this to the core of DMZ, because I don't see the general benefit.[/quote]

First, thank you for letting me know how I can extend DMZ with this function Smile

As for reasoning, it's solely to allow method-chaining when setting many properties in code. For instance if you want to register a new User from a form, in the form logic you have to do something like:

Code:
$user->username = $this->input->post('username');
$user->password = $this->input->post('password');
$user->email= $this->input->post('email');
$user->address = $this->input->post('address');
$user->phone= $this->input->post('phone');
$user->cellphone = $this->input->post('cellphone');
$user->carrier= $this->input->post('carrier');
$user->city= $this->input->post('city');
...ad ininitum...
$user->save();

Now if you collect 20 pieces of information, that gets to be a lot of copy-pasting. Now say you are going to create a form to allow the user to update their form info, but you only want some fields to be changeable - you have to copy/paste out this info again.

Now you have an admin form that allows the changing of entirely different information, or another special purpose form that requires a bit of different logic...

This just gets to be a lot of copy pasting, and I think method chaining allows less to be typed.

If this is a 'just me' thing I'm perfectly happy to extend DMZ with the function purely for my own uses - doesn't bother me a bit that it wouldn't be a core function - but then I don't know just how useful it would really be, so perhaps it just isn't worthwhile. I'm trying to ease the difficulty in making new forms, and perhaps this just isn't enough of an improvement to usability to be worthwhile, I dunno for sure.

I find forms to be the most time-consuming thing for me and am constantly trying to figure out how to make them more magic, less intensive, and I think DMZ is at the heart of how to do it - I just haven't figured out how exactly quite yet.

I'm just happy to know how it might actually be done - which you've answered and pointed me in the right direction for Smile

[eluser]OverZealous[/eluser]
@BrianDHall
Check out the Array extension. No copy-and-pasting, safe, and waaay easier:
Code:
$user->load_extension('array');
$user->from_array($_POST, array('username', 'password', 'email', 'address', ..));

[eluser]BrianDHall[/eluser]
Holy shiite, that's FANTASTIC! What a great function!

I knew DMZ was the right pick Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB