0

I have code (add custom field to post edit page):

    case 'text':
        echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', '<br />', $field['desc'];
        break;

I save it with the function:

foreach ($meta_box['fields'] as $field) {
    $old = get_post_meta($post_id, $field['id'], true);
    $new = $_POST[$field['id']];
    if ($new && $new != $old) {
        update_post_meta($post_id, $field['id'], $new);
    } elseif ('' == $new && $old) {
        delete_post_meta($post_id, $field['id'], $old);
    }

Everything works fine. So if field value exist it appear at the field value and if it doesn't exist it update this field with the new value (add to DB).

The trouble come when I want to add value by System with no ability for user to edit it. So I change first code to (add disabled):

<input type="text" disabled name="'

and now users are unable to edit.

At the post-edit-load there is default value in this field (ok) but it doesn't save value to DB. $new = $_POST[$field['id']]; now is empty.

Does someone have idea how to solve it?

Thank you.

1 Answer 1

0

disabled fields can't be submited, that is as is.

Change disabled to readonly and it will submit.

1
  • Excellent. Thank you Mihail! (Спасибо большое, Михаил!).
    – inno.vlad
    Jan 4, 2015 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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