1
function formexample_nameform(){

$form['user_name'] = array(
'#title' => t('your name'),
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);

return $form;
}

if i add this:

'#name' => 'new name attribute',

it looks like this:

function formexample_nameform(){

$form['user_name'] = array(
'#title' => t('your name'),
'#name' => 'new name attribute',
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);

return $form;
}

and it does not validate any more, it always let the inputs pass through.

my validate function:

function formexample_nameform_validate($form, &$form_state){
if ($form_state['values']['user_name'] == 'King Kong') {
    form_set_error('user_name',
    t('King Kong is not allowed')
    );
}
}

question: what has the name attribute with validation to do?!

| improve this question | | | | |
0

As per the FAPI the element textfield has no name attribute

Available Properties are

#access, #after_build, #ajax, #attributes, #autocomplete_path (default: FALSE), 
#default_value, #description, #disabled, #element_validate, #field_prefix, #field_suffix,
 #maxlength (default: 128), #parents, #post_render, #prefix, #pre_render, #process, #required,
 #size (default: 60), #states, #suffix, #text_format, #theme, #theme_wrappers, #title, 
#title_display, #tree, #type, #weight

I am not sure about the reason that the form is not validating, Excited to know the reason.

| improve this answer | | | | |
  • 1
    every standard textfield, generated with the API has a name attribute, if set it or not. question now is why the form does not validate if you change the value of the name attribute. (the reason should be off topic here) – user19578 Aug 4 '13 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.