We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43084
    • 34 Posts
    Note added at the end.

    Hello again!

    I hope someone can help me with a new problem I found. I am using the dob (Date of Birth) field in my Update Profile and Register forms in Login 1.8.1 for the user to set and modify. In order to solve a few format issues I followed the suggestions presented here:

    http://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257977

    This solution uses a pre-Hook in order to format the date correctly before the record is saved.
    Everything worked great following this suggestion, until I discovered that if the form fails validation in any field, the form reloads (asking the user to provide the appropriate information) but the date in the dob field gets scrambled even if this field was not modified. If I try to process the form as is, the dob field saves a blank (even when the datepicker widget shows 01-Jan-1970 ALWAYS). The user would have to set the date manually, even if he/she didn't want to modify it, which is troublesome. This happens, I believe, because the pre-Hook that formats the date correctly only runs if the form passes validation. Since validation fails, the pre-Hook never runs and the reloaded form doesn't know what to make of the dob value on its own.

    At first I tried to solve this with jQuery and running a script that formatted the field when the form was submitted. But since I'm using a specific locale to format the date, I don't want to add more variables from the side of the user's client configuration that may submit the date in an incorrect format.

    Now I'm thinking that the way to solve this is to run a snippet (with a code similar to that of my pre-Hook) that executes when the form fails validation and before the form reloads (or maybe just when the form is submitted, regardless of the outcome). Is there a way to do this easily without having to modify the Login code if possible?

    Thanks in advance for your time!

    EDIT: Sorry, I think I should had clarified that I'm using MODX Rev. 2.2.6. Is this the right thread for this question or should I try to post it at the Revo Discussions & Support Board?

    This question has been answered by pcamelo. See the first response.

    [ed. note: pcamelo last edited this post 11 years, 1 month ago.]
    • discuss.answer
      • 43084
      • 34 Posts
      Just in case someone is interested, I solved my problem by removing my prehook and instead adding a snippet in the page of my form with the following code:

      <?php
      if (!empty($_POST)) {
            if (isset($_POST["dob:required"])) {
              $_POST["dob:required"] = strtotime($_POST["dob:required"]);
              }
      }


      So this runs just after the form is submitted regardless of the outcome, which works even if the forms fails validation.

      Cheers!