I have a node form on which two fields are displaying. One is a list of radio buttons which is required field.
I am getting a value from url using arg(3)
and setting the default value of that field
$form['field_test'][LANGUAGE_NONE]['#default_value'] = arg(3);
I have a link field which is a multi valued field. It means this field as add another button
.
When I click on this add another button
and then submit the form, I see an error of Test field is required, and that default value of test field
gone.
Without clicking the add another button
everything works fine.
How can I set a default value of the test field in this case?
Code:
if (!$form['nid']['#value']) {
if (arg(3)) {
// Select the default value.
$tg = arg(3);
$form['field_test'][LANGUAGE_NONE]['#default_value'] = $tg;
}
}
// Make the field readonly.
$form['field_test'][LANGUAGE_NONE]['#attributes']['disabled'] = 'disabled';