1

I'm very glad that there is such a dedicated website for WP.

My problem is data validation upon saving attachment fields. I have added many custom fields to attachment/media library dialog, most of them are marked as mandatory. (Ex. $form_fields["some_custom_field"]["required"] = true;) But this just adds the class, but no validation or checking is done on WP side, so I want to check them myself with functions attached to attachment_fields_to_save filter. I can check and so on, BUT THE QUESTION IS: How to validate these fields, so if validation do not pas - WP returns an error in it's regular style, just like in registration form if you fill bad email.

In registration process in register_post action you can do this $errors->add('some_error_code', "<strong>Klaida</strong>: Nenurodėte įmonės kodo"); and it will not save data and return to visitor an error. I want that in saving attachment form :D

2
  • @Tommix - please do not post answers in the question. Post it as an answer and then accept it (you will have to wait 24 hours to accept it...), thanks :) Commented May 9, 2012 at 10:07
  • I'll do that when it will allow me :)
    – Tommixoft
    Commented May 9, 2012 at 11:31

2 Answers 2

1

THE ANSWER

Well as it happens many times in my life - i found the answer myself. For people who struggles as me here the answer:

$post['errors']['field_name']['errors'][] = __('Error text here.');

if you do that - error text will be displayed at the bottom of that field. In my case this doesn't work because i'm using inline media uploader, but with standard WP media uploader (the popup version) it's working just fine.

BTW best article about custom fields is here: http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/

0

I think this should help you: http://www.kevinleary.net/add-custom-meta-fields-media-attachments-wordpress/

1
  • Thanks for link but it doesn't help, there was nothing new to me. He did not do validation of data, which i need :)
    – Tommixoft
    Commented May 9, 2012 at 9:11

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.