WordPress.org

Forums

[Plugin: Custom Field Template] Required fields (3 posts)

  1. carolinem
    Member
    Posted 6 years ago #

    Love this plugin! I apologize in advance if these questions have already been asked... I've looked all over but couldn't find anything.

    Is it possible to set a field (or multiple fields) as required? Ie. a user must fill in a particular field or fields before successfully publishing their post.

    It would also be great if the fields were automatically labeled for accessibility in the backend (ie. <label for="somefield">Some Field:</label><input type="text" id="somefield">).

    Again, if this has already been addressed, please point me in the right direction. Thanks for a great plugin!

  2. Hiroaki Miyashita
    Member
    Posted 6 years ago #

    I am looking for some good ways to validate the field values.... This is a temporal way to set a field as required by use of JavaScript.

    Template Instruction

    <script type="text/javascript">
    jQuery('#save-post').click(function() {
    	if(!jQuery('.test').val()) { alert('Empty!'); return false; }
    });
    jQuery('#publish').click(function() {
    	if(!jQuery('.test').val()) { alert('Empty!'); return false; }
    });
    </script>

    Template Content

    [test]
    type = text
    size = 35
    class = test
  3. kk76
    Member
    Posted 5 years ago #

    Hi Hiroaki,

    This is great plug-in, however, I ran into some issues. I followed the same instructions, but when I leave the field empty, click on publish, it says empty. After I gave the value and click on publish, it still says empty. Please advice.

    This is my template content:

    [Attach]
    type = textarea
    rows = 4
    cols = 40
    tinyMCE = true
    mediaButton = true
    class = Attach

    [Post As]
    type = checkbox
    value = Anonymous
    valueLabel = Anonymous
    output = true

    This is template instruction:
    <script type="text/javascript">
    jQuery('#save-post').click(function() {
    if(!jQuery('.Attach').val()) { alert('Empty!'); return false; }
    });
    jQuery('#publish').click(function() {
    if(!jQuery('.Attach').val()) { alert('Empty!'); return false; }
    });
    </script>

    Thank you very much!!!

Topic Closed

This topic has been closed to new replies.

About this Topic