function formdefaults_edit_form_submit in Form Defaults 6.2
Same name and namespace in other branches
- 5.3 formdefaults.admin.inc \formdefaults_edit_form_submit()
- 7 formdefaults.admin.inc \formdefaults_edit_form_submit()
File
- ./
formdefaults.admin.inc, line 254
Code
function formdefaults_edit_form_submit($formid, &$form_state) {
$form_values = $form_state['values'];
$formid = $form_values['formid'];
$formdef = formdefaults_getform($formid);
// Reset fields
if ($_POST['op'] == 'Reset Selected') {
foreach ($form_values['fields'] as $field => $checked) {
if ($checked) {
unset($formdef[$field]);
}
}
// Condense addon array.
if ($formdef['#formdefaults_addon_fields']) {
$addons = (array) $formdef['#formdefaults_addon_fields'];
$new_addons = array();
foreach ($addons as $key => $field) {
if ($formdef[$key]) {
$i = 'formdefaults_' . count($new_addons);
if ($i != $key) {
$formdef[$i] = $formdef[$key];
unset($formdef[$key]);
if ($formdef[$key . '_markup']) {
$formdef[$i . '_markup'] = $formdef[$key . '_markup'];
unset($formdef[$key . '_markup']);
}
}
$new_addons[$i] = $field;
}
}
$formdef['#formdefaults_addon_fields'] = $new_addons;
}
}
if ($_POST['op'] == 'Add') {
$i = count((array) $formdef['#formdefaults_addon_fields']);
$key = 'formdefaults_' . $i;
$subkey = $key . '_markup';
$field = array();
$weight = $form_values['weight'];
switch ($form_values['field_type']) {
case "markup":
$field = array(
'#type' => 'markup',
'#value' => '',
);
$formdef[$key] = array(
'type' => 'markup',
'value' => '<p>Replace with your own markup</p>',
'format' => 0,
'weight' => $weight,
);
break;
case "fieldset":
$field = array(
'#type' => 'fieldset',
'#title' => 'Untitled',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
$subkey => array(
'#type' => 'markup',
'#value' => '',
),
);
$formdef[$key] = array(
'type' => 'fieldset',
'title' => 'Untitled',
'weight' => $weight,
);
$formdef[$subkey] = array(
'type' => 'markup',
'value' => '<p>Replace with your own markup</p>',
);
break;
}
$formdef['#formdefaults_addon_fields'][$key] = $field;
}
_formdefaults_save_form($formid, $formdef);
}