WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Front end validation` (22 posts)

  1. msteel
    Member
    Posted 3 months ago #

    Is there a way to do front end validation, hopefully with jQuery validate. I see there is some JS validation in the plugin, but it does not seem to work for me, even on a clean install of WP and Pods.

    I need to prevent the custom post type from saving if the required fields are not valid.

    Any help would be appreciated, thanks.

    https://wordpress.org/plugins/pods/

  2. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    Can you explain what your needs are as far as validation for the form are? Also what do you mean by "does not seem to work"? Are you getting an error or do you have an expectation that you are unable to fulfill?

  3. msteel
    Member
    Posted 3 months ago #

    Thanks for the quick reply. What I meant by "does not seem to work" is that when I attach requirement to a field, say a simple text field, and submit the form I get an error in my console.

    POST http://local.blah.com/email-templates/wp-admin/post.php 500 (Internal Server Error)

    That error does not appear if I remove the requirement, so it seems as if something is trying to happen, but failing.

    Doing a little debugging in jquery.pods.js I can see that the script loads by adding a console.log statement but another console.log within the validate method never fires, so I'm not sure what would be causing the 500 error to begin with (and as I mentioned, it is only there when there is a required field)

  4. msteel
    Member
    Posted 3 months ago #

    I should I add, I realize jquery.pods.js validate might be for creating pods, I'm not sure, I'm still ramping up on pods. Loving the plugin, it really is fantastic.

  5. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    Can you share the code that you added please? I will have some one take a look and give you some feedback and direction.

  6. msteel
    Member
    Posted 3 months ago #

    You mean the code to jquery.pods.js?

    That is simply the console.log statements here...
    
    ( function ( $ ) {
    	console.log('one');
        var pods_changed = false,
            pods_form_field_names = [],
            methods = {
                validate : function () {
    				console.log('two');
                    var $containers = $( 'form.pods-submittable, .pods-validation' ),
                        form_fields = 'input.pods-validate, select.pods-validate, textarea.pods-validate';

    This is on a fresh install of WP and Pods.

  7. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    No I meant the code you are adding to attempt to add validation. Sorry I was not clear.

  8. msteel
    Member
    Posted 3 months ago #

    I guess my question is, "Is front end validation via javascript something Pods does or is it something I need to develop?"

  9. msteel
    Member
    Posted 3 months ago #

    I'm just looking for closure on this. If front end validation is something I need to do I'm happy to do so and try and make it something I can contribute somewhere.

    Thanks,

    -Marc

  10. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 3 months ago #

    Pods handles it's own validation, but you can use jQuery validation on-top of it when using the public forms. Our validation happens server-side, and we send back an error during processing.

    The error 500 isn't something that's normal, so you may want to report that bug on our GitHub and we can work through what exactly is causing that.

  11. msteel
    Member
    Posted 3 months ago #

    OK, thanks. I've been working on a plugin to handle the validation. I should have it up on GitHub later today or tomorrow and will let you know in case you have any interest in checking it out. It's working quite well for my needs so far.

  12. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    Yes, please share the link here.

  13. msteel
    Member
    Posted 3 months ago #

    It still has a ways to go but it seems to work well for most field types. Relation fields and color pickers might need some special love, but in general I'm happy with the start of this. I'm curious what you think.

    https://github.com/mpsteel/pods-validation

    Thanks!

  14. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    This looks very promising. Thanks for your work on this. I have not had a chance to test this out yet, just to look at the code. Two things that jumped out at me:

    This plugin will generate fatal errors if Pods isn't activated. You should set your code to only run if Pods is active. I cover how to do this in my series on creating Pods plugins. We have a full starter plugin for Pods plugins, as well as a simple example of how to safely add code dependent on Pods.

    You are prefixing your php functions with Pods. It is best practice for an add-on plugin to have its own prefix, that way you avoid using a function name that Pods uses, or may use in the future.

    I will take a more detailed look at the plugin tomorrow and provide any additional feedback I can.

  15. msteel
    Member
    Posted 3 months ago #

    Thanks for this, yeah I was anxious to get the core functionality down, I'll make it more formal. I've just updated the picks functionality. I know WYSIWYG is not firing properly. I'm sure there'll be more. Always more... :)

  16. msteel
    Member
    Posted 3 months ago #

    The plugin has been updated to follow your Pods plugin framework.

    https://github.com/mpsteel/pods-validation

  17. msteel
    Member
    Posted 3 months ago #

    Has anyone had a chance to try this plugin?

    Thanks,

    -M

  18. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    Sorry, I did not get a chance to try this yet. Can you please provide some information on how it works? Do I need to define what my validation conditions are for my fields?

  19. msteel
    Member
    Posted 3 months ago #

    You do not need to define anything. I have gotten all fields to validate simply by enabling the plugin.

    When the form is submitted an ajax request is fired submitting the form fields. Any form fields that belong to the pod are validated in one of two ways. If a field is required and has a blank value it is flagged and the form field is highlighted. If somehow that does not suffice it passes off to the Pods API handle_field_validation method.

    Any field that was flagged will be updated upon change and re-validation.

    When there are no errors the form process continues.

  20. Josh Pollock
    Member
    Plugin Author

    Posted 3 months ago #

    It seams to work well for front-end forms. Very cool.

    Two important things I saw:
    1) You should move everything into the root level of the GitHub repo, that way it can be installed directly from the download or a Git clone.
    2) This is running both in front-end and back-end. It prevented me from publishing a post. I would recommend only running this in the front-end. You can probably just wrap the action in !is_admin() to fix that.

    Also, I was thinking a cool enhancement once you have your first version down would be to allow users to add additional conditions and warning messages on a per field basis.

  21. msteel
    Member
    Posted 3 months ago #

    Thanks for the reply, I updated Git.

    As for front-end/back-end, I wanted this to validate on the admin side, but have the validation happen in the browser, before the user receives a wp_die.

    I initially thought about making it jQuery Validation oriented, but I really wanted to bring the Pods validation to the front so that our users wouldn't be endlessly hitting Back to fix another field on a form.

    And as for the Pods validation, this question has been killing me.. is it ever possible to trigger some of the basic validation such as on the text and email fields.

    This never worked for me...
    if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {

    I had to try (and this was a couple of weeks ago, so I think...
    if ( ! strlen( $value ) && strlen( $check ) < 1 ) {

    I think I kept the $check in from the pre save.

  22. msteel
    Member
    Posted 2 months ago #

    Any chance for an answer to my last question? Thanks.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.