Meta Box
Support Forum
Support › Meta Box Builder › Validation for data uniquenessResolved
How to validate a field data see if it's unique? For example, I would like to force stock# field unique.
Hi,
Do you mean the field value is unique in the database? You can use the validation rule remote to check the field value with a PHP function.
remote
Refer to these topics to know how to use https://support.metabox.io/topic/remote-validation-example/ https://stackoverflow.com/questions/22814260/wordpress-how-to-add-a-post-meta-keeping-the-value-unique
So should I input the rule to this value field? https://share.getcloudapp.com/nOul4bXy
I do understand how to check in PHP via ajax but not sure how to send in the frontend.
You should use the code to validate the field value and refer to this topic https://support.metabox.io/topic/remote-validation-example/.
If you are using the extension MB Frontend Submission, it works as same as on the backend.
So I should input something like these to the value field of validation section? https://share.getcloudapp.com/z8uP9bpq
I think I got it. I should set this to the value field, right? it worked. admin-ajax.php?action=validate_stock_no
https://share.getcloudapp.com/jkuejRwW
One more question, how do I check the id of the post that is sending remote validation in PHP?