• Hello. I have inherited a very messy plugin which leverages a PHP “framework” called GeoLib. I think that’s where the problem is, but i’m not sure.

    This plugin interacts with a database for an apple farm about picking apples. At basically step 1 of this plugin’s functionality, it’s asking for a date of entry. The date picker is apparently where it’s breaking down. When the data is posted, the entered date is returned invalid. E.g.
    "2022-01-09T15:31" is not a valid date.

    I can change that value in the HTML input field to the following format (basically just removing the “T” before the Time, and putting it into 12-hr format… for whatever reason). Obviously, that defeats the purpose of the date picker. Changing the input field, manually after the error, and submitting again with the following format is accepted:
    2022-01-09 03:31 PM

    • This topic was modified 2 years, 5 months ago by ajaxStardust. Reason: add external link reference
    • This topic was modified 2 years, 5 months ago by ajaxStardust.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    Ideally the date picker would be configured to return an acceptable date. If that’s not possible, the format could be converted at some point before the validation step. For example, PHP can convert nearly any date string into a timestamp with strtotime(), then a timestamp can be formatted in any manner you like with date().

    If the validation is being done client side with JavaScript, there are equivalent JavaScript functions you could use to do the same.

    How you would insert this conversion step into the data flow depends on how that actually happens. Ideally there’d be a filter or action hook to use. Otherwise it may require directly altering the source code that’s involved.

    Thread Starter ajaxStardust

    (@ajaxstardust)

    Thank you for your reply!

    [ EDIT – it is NOT the jQuery. i forgot i added that comment line, which is not appearing in the view source ]

    I think it has something to do with some custom jQuery code, but i’m not sure.

     jQuery(document).ready(function($){        
            
            // Setup - add a text input to each footer cell
            $('#users tfoot th').each( function () {
                var title = $('#users thead th').eq( $(this).index() ).text();
                $(this).html( '<input type="text" placeholder="'+title+'" /><!-- line 135 -->' );
            } );
         
          

    I’ll have to debug again. As far as I could tell, Chrome’s inspector is telling me that $('#users tfoot th').each( function () is not a function.
    What dev tool might you recommend for debugging this?

    • This reply was modified 2 years, 5 months ago by ajaxStardust.
    • This reply was modified 2 years, 5 months ago by ajaxStardust.
    • This reply was modified 2 years, 5 months ago by ajaxStardust.
    • This reply was modified 2 years, 5 months ago by ajaxStardust. Reason: revision - this is NOT the issue
    Thread Starter ajaxStardust

    (@ajaxstardust)

    Sorry. My reply didn’t make sense.

    In other words. I think the date is being messed up by jQuery, or the jQuery code is what’s converting it to 12 hr format.

    It’s just proven quite difficult for me to even find where i can evaluate the date data in the PHP code. I don’t see any date specific functions in the PHP for this plugin.

    @bcworkz when you say “validation step”, are you referring to a specific function in the WP core code?

    • This reply was modified 2 years, 5 months ago by ajaxStardust.
    Moderator bcworkz

    (@bcworkz)

    Validation step as in what ever is responsible for the message ‘”2022-01-09T15:31″ is not a valid date.’ If the date can be made into a valid format before this point, all should be well. I don’t even know if it’s client side or server side.

    You can use your browser’s developer tools to help you debug JavaScript and jQuery (sources tab). You can set breakpoints and watch variable values. Less sophisticated but still often effective would be to simply insert console.log() calls at strategic points in the code that tell you the value of key variables.

    On the PHP side, the equivalent to console log is error_log(). Unless you have an integrated development environment set up, logging or outputting messages is about all you can do to debug PHP code. It helps a lot to have a test site installed on localhost to assist in debugging PHP. It then becomes much easier to frequently edit source code as is often necessary in debugging work.

    Thread Starter ajaxStardust

    (@ajaxstardust)

    Thank you very much for your thoughtful reply!

    I think I need to do some Unit testing. Never done it w/ PHP before, but this seems like a perfect opportunity to learn. Have you any recommendations for PHP Unit testing with WordPress? Would you recommend I pursue this route?

    • This reply was modified 2 years, 5 months ago by ajaxStardust.
    Moderator bcworkz

    (@bcworkz)

    There is a large suite of unit tests for core WP code. Unit testing is required for all contributions to core. IMO, unit testing for a custom breadcrumb function is probably overkill. But if you want to be a PHP developer, it is something that you’ll want to learn and you have to start somewhere ??

    Generic PHPUnit tutorial.

    Thread Starter ajaxStardust

    (@ajaxstardust)

    Thank you very much, @bcworkz
    I look forward to being part of the www.ads-software.com community.
    best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Date Format – Invalid – How to correct?’ is closed to new replies.