SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PEAR quickform2 checkbox

    How do I set a checkbox element which is already checked in quickform2?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Docs suggest it goes in as $data array, though I cannot confirm as I have not tested it.

    This post I found then suggests you have to implicitly tell is to be checked, using chaining, beware though the Q was posed with Quickform and not Quickform2 - so may not applicable.

    Like I say, all rather much guesswork, but I'm quite interested by QF2.

    EDIT

    Ah, yes - confirmation and a link to the correct part of the api docs.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spent ages with this and nothing seems to work. I can set the value in $data array but the checkbox remains unchecked.
    Web searches suggest this
    PHP Code:
    $promos $fieldset->addElement('checkbox''promos', array('value' => '6''checked' => 'checked'), array('label' => 'I would like to receive emails')); 
    but it still doesn't check the box.

    Think its time for an alternative approach. Anybody able to recommend an alternative to quickform which will allow me to set rules and validate the form in a similar manner but without these problems?

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So did you try the solution I posted for you?

    append (chain) this method:

    [your declaration and then]->setChecked(true);
    PHP Code:
    // maybe if I show you exactly

    $promos $fieldset->addElement('checkbox''promos'
                    array(
    'value' => '6''checked' => 'checked'), 
                    array(
    'label' => 'I would like to receive emails'))->setChecked(true); 

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, tried that and it returns an error

    Fatal error: Call to undefined method HTML_QuickForm2_Element_InputCheckbox::setChecked()

    Cant figure this out as I have
    PHP Code:
     require_once 'HTML/QuickForm2/Element/InputCheckbox.php'
    at the top of the page so would have expected it to have found it.

    I have also tried instantiating and echo a new object
    PHP Code:
    $checkbox = new HTML_QuickForm2_Element_InputCheckbox(nullnull, array('checked' => 'checked'));
            echo 
    $checkbox
    This returns the checkbox but it is still unchecked.
    Any thoughts appreciated.

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sorry mate, I'm out of ideas and I just don't have the time to download this and test it for you.

    Anyone else?

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At last this seems to be getting close to what I want giving achecked box with value 6
    PHP Code:
    $checkbox = new HTML_QuickForm2_Element_InputCheckbox('promos', array('checked' => 'checked''value' => '6'));
            echo 
    $checkbox
    Cups, I appreciate what you say about not having time.....
    Spent too long on this myself.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •