Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Tab Ordering on a PHP created Form


Go to End


3 Posts   2895 Views

Avatar
merrick_sd

Community Member, 99 Posts

27 January 2011 at 11:01pm

how can i set the tab order on a form that is creating in a php file.

I can't tab through the credit card field ...it keeps jumping on to cvv2Number.

Here's my code

function getPaymentFormFields() {
$mt = array('mm','01','02','03','04','05','06','07','08','09','10','11','12');
// lil loop so $yr will always contain this year +/- 5 years;
$yr = array(0=>'yyyy');
for ($x = (date('Y') - 5); $x <= date('Y') + 5; $x++) {
$yr[$x] = $x;
}
$issu = array('01','02','03','04','05');
$cardvalue = array('0','1','9','S','8');
$cardname = array(
'Visa' => 'Visa',
'MasterCard'=> 'MasterCard',
'Switch' => 'Switch',
'Solo' => 'Solo',
'Other' => 'Other'
);

return new FieldSet(

new DropdownField('creditCardType','Card Type', $cardname, $cardvalue),
new CreditCardField("CreditCardNumber", "Credit Card Number:"),
new DropdownField('expDateMonth','Expiration Date', $mt, $mt),
new DropdownField('expDateYear','', $yr, $yr),
new LiteralField("extrafields", '<div id="extrafields" style="display:none;">'),
new DropdownField('startDateMonth','Start Date', $mt, $mt),
new DropdownField('startDateYear','', $yr, $yr),
new DropdownField('cardIssue','Issue No', $issu, $issu),
new LiteralField("extrafields", '</div>'),
new NumericField("cvv2Number", "Card Verification Number:", "", 3),
new LiteralField("cvv2img", '<img src="/themes/winderworld/images/cvv2.gif" id="cvvimage" alt="cvv2" />')

);
}

Avatar
swaiba

Forum Moderator, 1899 Posts

27 January 2011 at 11:49pm

The tab order will be in the order that the fields are rendered I believe, you could create your FormField items and ->setTabIndex() manually on each one.

Avatar
merrick_sd

Community Member, 99 Posts

28 January 2011 at 1:20am

Thanks, i saw that in docs but not sure how and where i'd use it exactly

new DropdownField('creditCardType','Card Type', $cardname, $cardvalue),

creditCardType->setTabIndex(99)

I usedjQuery in the end, which saved altering php, but a little example of setTabIndex in use would help.

thanks to
http://greatwebguy.com/programming/dom/setting-your-tabindex-on-your-html-forms-automatically-with-jquery/