Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to use $Sender->Form->Dropdown properly?

Hello all,

I'm very inexperienced with PHP, but I have successfully modified some other people's work up to this point. I'm following the tutorial on the wiki pages located here: http://vanillawiki.homebrewforums.net/index.php/Practical_Example:_How_to_Extend_Existing_Forms

So far I have successfully added a few new custom fields for the Profile. I've also got this working using ProfileExtender, so I'm aware of that plugin, but I"m writing my own to gain some knowledge about plugins, PHP, and to fully customize for my users.

My question is hopefully fairly simple:

I've added a few fields, and the one that is giving me trouble is entered via Form->Dropdown.

public function ProfileController_EditMyAccountAfter_Handler($Sender) { echo '<li>'; echo $Sender->Form->Label(T("GT (testing)"), 'GT'); echo $Sender->Form->TextBox('GT', array('class' => 'InputBox SmallInput')); echo '</li>'; echo '<li>'; echo $Sender->Form->Label(T("PP (testing)"), 'PP'); echo $Sender->Form->Dropdown('PP', array('RW','LW','C','LD','RD')); echo '</li>'; }

The "PP" field works, and shows up on Edit Profile with the fields I've designated. However, once a user makes his choice, it's saved in the db as a numerical value, and thus when Viewing their profile, the numerical value is shown.

The column is varchar(64) in the database, so I'm thinking it has to do with the Dropdown() functionality -- I kind of just took a stab at it... I'm not sure where to find documentation on how to use it properly.

Anyways, if I'm missing anything obvious, I apologize in advance, I'm completely new to all of this.

Comments

  • Ok, so found this info in the core/class.form.php file:

    /** * Returns XHTML for a select list. * * @param string $FieldName The name of the field that is being displayed/posted with this input. It * should related directly to a field name in $this->_DataArray. ie. RoleID * @param mixed $DataSet The data to fill the options in the select list. Either an associative * array or a database dataset. * @param array $Attributes An associative array of attributes for the select. Here is a list of * "special" attributes and their default values: * * Attribute Options Default * ------------------------------------------------------------------------ * ValueField The name of the field in 'value' * $DataSet that contains the * option values. * TextField The name of the field in 'text' * $DataSet that contains the * option text. * Value A string or array of strings. $this->_DataArray->$FieldName * IncludeNull TRUE to include a blank row FALSE * String to create disabled * first option. * InlineErrors Show inline error message? TRUE * Allows disabling per-dropdown * for multi-fields like Date() * * @return string */

    for public function DropDown

    So it sounds like I'm setting up my DataSet (array) improperly, I'll start looking into that some more. Can anyone else shed some light?

  • peregrineperegrine MVP
    edited August 2014

    so the associative array that I suggested before didn't work

    echo $Sender->Form->Dropdown('PP', array(
              "RW"=>"RW",
               '"LW"=>"LW",
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine said:
    so the associative array that I suggested before didn't work

    echo $Sender->Form->Dropdown('PP', array(
              '"RW"=>"RW",
               '"LW"=>"LW",
    

    Oh... I think I missed an extra single quote there, it was just failing. Let me try fixing that.

  • Got it working! Thank you. It had a syntax problem (missing an end paren)

  • echo $Sender->Form->Dropdown('PP', array(
    "RW"=>"RW",
    '"LW"=>"LW",
      etc.
    

    doesn't matter single or double quotes they just need to match

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • another example

    $Options = array('0' => T('Authors may never edit'),
                            '350' => sprintf(T('Authors may edit for %s'), T('5 minutes')), 
                            '900' => sprintf(T('Authors may edit for %s'), T('15 minutes')), 
                           '3600' => sprintf(T('Authors may edit for %s'), T('1 hour')),
                          '14400' => sprintf(T('Authors may edit for %s'), T('4 hours')),
                          '86400' => sprintf(T('Authors may edit for %s'), T('1 day')),
                         '604800' => sprintf(T('Authors may edit for %s'), T('1 week')),
                        '2592000' => sprintf(T('Authors may edit for %s'), T('1 month')),
                             '-1' => T('Authors may always edit'));
             $Fields = array('TextField' => 'Text', 'ValueField' => 'Code');
             echo $this->Form->Label('Discussion & Comment Editing', 'Garden.EditContentTimeout');
             echo $this->Form->DropDown('Garden.EditContentTimeout', $Options, $Fields);
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited August 2014

    Moving to a new topic...

Sign In or Register to comment.