drupal - 创建只有月份和年份的日期字段 - Drupal

标签 drupal drupal-forms

我正在 Drupal 中创建信用卡表格。我需要一个日期选择字段,用户可以在其中选择他们的信用卡到期日期,该日期仅包含月份和年份 - 没有日期。

Drupal 表单 #type 'date' 产生一个日期选择器,它有 day-month-year选项。我只需要month-year .有什么帮助吗?

最佳答案

使用 Date API 模块(Date module 的一部分),你可以做这样的事情......

<?php
$form['payment_expirationDate'] = array(
    '#type' => 'date_select',
    '#title' => t('Expiration Date:'),
    '#date_format' => 'm-Y',
    '#default_value' => $expirationDate,
    '#date_year_range' => '-1:+10',
    '#required' => TRUE,
    '#date_label_position' => 'within'
 ); 
?>

date_select 类型将为您的字段提供选择框表单元素。 #date_format 数组键允许您使用 PHP 日期格式字符串来控制出现的选择框以及其中的内容。

关于drupal - 创建只有月份和年份的日期字段 - Drupal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5229654/

相关文章:

mysql - Drupal 数据库 API 增量

php - Drupal 7 错误导致 php 最大超时

drupal - 将附件下载到一个文件中

drupal - 如何在 View 批量操作期间显示附加表单?

forms - 在 Drupal 7 中向表单添加文本(只是文本!)

drupal - 在Drupal 7表单API中-如何创建 "button"类型的输入(不是 "submit")?

mysql - 如何将图像从 Drupal 字段加载到 UIImageView?

html - Drupal错误信息的定位

Drupal 保存数据 hook_form_alter