function editablefields_submit in Editable Fields 6
Same name and namespace in other branches
- 6.3 editablefields.module \editablefields_submit()
- 6.2 editablefields.module \editablefields_submit()
Menu callback: ajax submit.
2 string references to 'editablefields_submit'
- editablefields_menu in ./
editablefields.module - Implementation of hook_menu().
- theme_editablefields_formatter_editable in ./
editablefields.module - Theme the editable field.
File
- ./
editablefields.module, line 191 - Editable fields module.
Code
function editablefields_submit() {
$nid = $_POST['nid'];
$field_name = $_POST['field'];
$delta = $_POST['delta'];
$node = node_load($nid);
if (node_access('update', $node)) {
if (!isset($_POST[$field_name])) {
$_POST[$field_name] = array();
}
$form_state = array(
'values' => $_POST,
);
if (is_array($node->{$field_name})) {
drupal_execute('editablefields_form', $form_state, $node, $field_name, $delta);
$err = drupal_get_messages();
if (count($err) > 0) {
drupal_set_header('HTTP/1.1 404 Not Found');
// format the error message suitable for a popup window in simple text.
foreach ($err as $type => $messages) {
foreach ($messages as $message) {
print $type . ' : ' . $message . "\n";
}
}
exit;
}
$field = content_fields($field_name);
if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
if ($node->{$field_name}[$delta] != $form_state['values'][$field_name][0]) {
$node->{$field_name}[$delta] = $form_state['values'][$field_name][0];
node_save($node);
}
}
else {
if ($node->{$field_name} != $form_state['values'][$field_name]) {
$node->{$field_name} = $form_state['values'][$field_name];
node_save($node);
}
}
// make sure sensible headers etc are sent...
drupal_set_header('Content-Type: text; charset=utf-8');
}
else {
drupal_set_header('HTTP/1.1 404 Not Found');
print t('No field found, of name: %field', array(
'%field' => $field_name,
));
}
}
else {
drupal_set_header('HTTP/1.1 404 Not Found');
print t('No write permissions for %field', array(
'%field' => $field_name,
));
}
exit;
}