private function set_validation_member_field_birthday() { if (!$this->check_is_enabled_member_field('birthday')) { return false; } $properties = Form_Util::get_model_field('member', 'birthyear'); $attrs = $properties['attributes']; $attrs['value'] = isset($this->member_obj->birthyear) ? $this->member_obj->birthyear : date('Y'); if (self::conf('birthday', 'birthyear.isRequired')) { $properties['rules'][] = 'required'; } $this->validation->add('member_birthyear', $properties['label'], $attrs, $properties['rules']); list($month, $day) = !empty($this->member_obj->birthday) ? Util_Date::sprit_date_str($this->member_obj->birthday) : array(1, 1); if (self::conf('birthday', 'birthday.isRequired')) { $rules[] = 'required'; } $options = Form_Util::get_int_options(1, 12); $rules = array(array('valid_string', 'numeric'), array('in_array', array_keys($options))); $this->validation->add('member_birthday_month', '誕生日(月)', array('type' => 'select', 'options' => $options, 'value' => $month), $rules); $options = Form_Util::get_int_options(1, 31); $rules = array(array('valid_string', 'numeric'), array('in_array', array_keys($options))); $this->validation->add('member_birthday_day', '誕生日(日)', array('type' => 'select', 'options' => $options, 'value' => $month), $rules); }
function form_date(Validation $val, $label, $name_month, $name_day, $label_col_sm_size = 2, $help = '', $optional_public_flag = array(), $def_val_month = null, $def_val_day = null) { $fields = array(); $atters = array(); $options = array(); $names = array('month', 'day'); foreach ($names as $name) { $val_name = 'name_' . $name; $val_name = 'name_' . $name; $fields[$name] = $val->fieldset()->field(${$val_name}); $atters[$name] = array('id' => Site_Form::get_field_id($name), 'class' => 'form-control'); if ($fields[$name]->get_attribute('required') == 'required') { $atters[$name]['required'] = 'required'; } $val_name = 'def_val_' . $name; if (!is_null($fields[$name]->get_attribute('value'))) { ${$val_name} = $fields[$name]->get_attribute('value'); } elseif (is_null(${$val_name})) { ${$val_name} = 1; } $options[$name] = !is_null($fields[$name]->get_options()) ? $fields[$name]->get_options() : Form_Util::get_int_options(1, $name == 'month' ? 12 : 31); } $data = array('val' => $val, 'name_month' => $name_month, 'name_day' => $name_day, 'def_val_month' => $def_val_month, 'def_val_day' => $def_val_day, 'label' => $label, 'options' => $options, 'atters' => $atters, 'is_required' => !empty($atters['month']['required']) && !empty($atters['day']['required']), 'label_col_sm_size' => $label_col_sm_size, 'help' => $help, 'optional_public_flag' => $optional_public_flag); return render('_parts/form/date', $data); }