Re: QuickForm, problem setting defaults on select
| From: | Ian Warner | Date: | Mon, 16 Oct 2006 05:04:44 +0000 |
| Subject: | Re: QuickForm, problem setting defaults on select | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25461@lists.php.net to get a copy of this message | ||
Louie Miranda wrote:
Its.. // Set defaults for the form elementsTo be honest I dont know why you have blank options - ""=>"", ?? If you want the default to be VISA then place it first in the list this is the easiest manner - however if you are drawing a customer from a database who already has a predefined card and you want to show Mastercard then use the below: This code works perfectly for me : One issue - 'class' => 'txt_blk11px_b' you had --- 'class' => txt_blk11px_b now I dont think this is a constant as they should be capitalised so should be quoted. Providing some debugging as below helps and is what I was asking - what are the VALUES returned for the variables - are they coming from a DB are you setting them up. $custom_name = 'Ian Warner'; $cc_account = 'Personal'; $cc_type = 'MASTERCARD'; $cc_expm = '9'; $cc_expy = '2008'; $type_of_account = array('' => '', 'Office' => 'Office', 'Personal' => 'Personal'); $type_of_cards = array('' => '', 'VISA' => 'VISA', 'MASTERCARD' => 'MASTERCARD', 'AMEX' => 'AMEX'); $form->setDefaults( array( 'custom_name' => $custom_name,$form->setDefaults( array( 'custom_name' => $custom_name, 'cc_account' => $cc_account, 'cc_type' => $cc_type, 'CCexpiry' => array('F'=>$cc_expm, 'Y'=>$cc_expy), ));As for the $cc_account, it is just normally. "Office" or "Personal". And as for the $cc_type, (VISA, MASTERCARD, AMEX) $type_of_account = array(""=>"", "Office"=>"Office","Personal"=>"Personal"); $type_of_cards = array(""=>"", "VISA"=>"VISA", "MASTERCARD"=>"MASTERCARD", "AMEX"=>"AMEX");
'cc_account' => $cc_account,
'cc_type' => $cc_type,
'CCexpiry' => array('F' => $cc_expm, 'Y' => $cc_expy)));
$form->addElement('text', 'custom_name', 'Custom Name', array('size' => 50, 'maxlength' => 255, 'class' => 'txt_blk11px_b'));
$form->addElement('select', 'cc_account', 'Type of Account', $type_of_account);
$form->addElement('select', 'cc_type', 'Type of Card', $type_of_cards);
$form->addElement('date', 'CCexpiry', 'Credit Card Expiration',
array('format' => 'F-Y',
'minYear' => date('Y'),
'maxYear' => date('Y') + 10));
Justin answered my next query what version of QF do you run
do a "pear upgrade-all" on your local PEAR - do this regularly. Use single quotes also for strings
I was thingking, is $form->setDefaults() the correct way to display the select?. Well, it worked fine on the dates though. Louie On 10/16/06, Ian Warner <iwarner@triangle-solutions.com> wrote:Louie Miranda wrote:Oh im sorry, it shouldnt be there. It was part of my tests awhile ago. It should only be.. $form->addElement('select', 'cc_account', 'Type of Account', $type_of_account);And the values you are using please. Just copy your whole page in if possible please.Louie On 10/16/06, Ian Warner <iwarner@triangle-solutions.com> wrote:Hello, i tried to find first the archives and tried different settingsLouie Miranda wrote:make it work. But could not. OK, here is what i have tested.. My code is..to// Set defaults for the form elements $form->setDefaults( array( 'custom_name' => $custom_name, 'cc_account' => $cc_account, 'cc_type' => $cc_type, 'CCexpiry' => array('F'=>$cc_expm, 'Y'=>$cc_expy), ));$type_of_account = array(""=>"", "Office"=>"Office",Can you give me the values of all of the above please.$form->addElement('text', 'custom_name', 'Custom Name', array('size' => 50,"Personal"=>"Personal"); $type_of_cards = array(""=>"", "VISA"=>"VISA", "MASTERCARD"=>"MASTERCARD", "AMEX"=>"AMEX");you$type_of_cards);'maxlength' => 255, 'class' => txt_blk11px_b)); $form->addElement('select', 'cc_account', 'Type of Account', $type_of_account, $cc_account); $form->addElement('select', 'cc_type', 'Type of Card',$form->addElement('select', 'cc_account', 'Type of Account', $type_of_account, $cc_account); You have 5 values in here - cant remember what the 5th does but do$form->addElement('date', 'CCexpiry', 'Credit Card Expiration', array('format' => 'F-Y','minYear' => date('Y'), 'maxYear' => date('Y') + 10));setDefaults, works on my input field custom_name and select CCexpiry.need it?its weird that it does not work on field name cc_account and cc_type.Nowfollowing $cc_account and $cc_type is just a single value (not array). Am i missing something here?The