Quickform

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benry
Forum Newbie
Posts: 2
Joined: Mon Jul 24, 2006 5:27 am

Quickform

Post by benry »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Am just branching out into PEAR and OO in general and having a bit of a problem with QuickForm which I am sure is because I am an idiot.

Am trying to have a check box which is set according to a value in a db. If the isLive field is set I want the box to be checked. If it isn't I want the box to be unchecked.

This is the code

Code: Select all

// instantiate a new form
$form = &new HTML_QuickForm('edit', 'post');

// build the form 
$form->addElement('date', 'date', 'Crossword date', $options);	
$form->addElement('text', 'solutionAcross', 'Solution across', array("size" => 40, "value" =>  "{$row['solutionAcross']}"));	
$form->addElement('text', 'solutionDown', 'Solution down', array("size" => 40, "value" =>  "{$row['solutionDown']}"));
$form->addElement('text', 'clueAcross', 'Clue across', array("size" => 40, "value" =>  "{$row['clueAcross']}"));
$form->addElement('text', 'clueDown', 'Clue down', array("size" => 40, "value" =>  "{$row['clueDown']}"));
$form->addElement('text', 'hint', 'hint', array("size" => 40, "value" =>  "{$row['hint']}"));
$form->addElement('advcheckbox', 'isLive', 'Queued to go live', NULL, NULL, array(1,0));

$checked=FALSE;
if ($row['isLive']) $checked = TRUE;

$form->setChecked($checked);

$form->addElement('submit', 'btnSubmit', 'Submit');	
$form->addElement('hidden', 'crosswordID', $crosswordID);


$row is an array containing variables sucked out of a db

except it errors out with
Fatal error: Call to undefined function: setchecked()

The rest of the form is just fine.

Clearly I am cocking it up - would just be v grateful if someone could point me in the right direction. I have tried to find any help I can, but the manual on PEAR isn't quite as helpful (or rather pre-supposes more knowledge) than the PHP manual does.

Many thanks in advance.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

setChecked() is a method of the Element not Form. Look at createElement() to create an instance of Element.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Then read this:

viewtopic.php?t=8815
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

If that is too confusing for now, this should work ... (Depending on which version of QuickForm)

Code: Select all

if ($checked) {
    $form->setDefaults(array('isLive' => 'checked'));
}
benry
Forum Newbie
Posts: 2
Joined: Mon Jul 24, 2006 5:27 am

QuickForm - thanks and apols

Post by benry »

Firstly - apologies for cocking up on the code posting - mea culpa. Sorry about that. I should have read the rules first.

Secondly - thank you very much indeed for the helping hand - it works! You got me out of a hole


Thank you
Post Reply