Adding code to forms

We need to place get_current_user on a field and we also need to place DATE_now and TIME_now on a form since we need to capture the username, plus actual date and time of submitting the form... Is that possible?

  • jnkfrancis

    Hi Fabio,

    I'm here to take a look at your request. So it sounds like you want to get some specific user data sent to you when someone sends in a form.

    If you go to Forminator > Forms, then find the form you wish to edit.

    On that form click the "Edit" button. Then scroll down and click on "Form Settings". Then click on "Emails".

    There you can edit the format of the emails that you receive and you can add some very useful fields. If you click on the blue icon in the upper left-hand corner of the editor (see screenshot) you will find a number of useful fields that you can insert into the email.

    Screenshot: https://drive.google.com/file/d/1u57wJgd42pe1vaAgjE5j8vV2VaYzeVdK/view?usp=sharing

    For example, in your case, you could use any of these:
    - {user_name}
    - {user_email}
    - {user_login}
    - {date_mdy}
    - {date_dmy}.

    It looks for the moment there isn't a built-in field to enter the time, however, in the "Submissions" section you can see the exact time and date the form was sent.

    Take a look at those settings and see if they work for what you are planning on, and if you need more help, let us know.

    Jeremy

  • Fabio Fava

    Hey jnkfrancis thank you for your reply!

    I neeed Date, Time and Display Name to be exhibited on the form (but not editable), so the person can see this data but not edit them. I got to the place you told me but the fields aren't shown at the Form Preview... I'm probably messing up in some point... I'll keep looking forward from you on that, thank you very much for your help.

    Cheers!

  • jnkfrancis

    Hi Fabio,

    Thanks for clarifying :slight_smile: . Let's try this:

    On the form editor (Forminator Pro > Forms - click "Edit" on the form you want to edit.) You are going to want to add an HTML field to your form.

    Then in the editor switch to text mode and then you can use the "Add Form Data" button to add in the placeholders as I mentioned in the earlier response.

    Screenshot: https://drive.google.com/file/d/1c4s2M97wTkgQuJ14HLA60zhps9h0CYwa/view?usp=sharing

    You will want to use:

    {user_name} - {date_mdy}

    Now Forminator doesn't have an option for time, but we can add that with a bit of custom code

    <span id="clock"></span>
    
    <script>
    var clockElement = document.getElementById( "clock" );
    
    function updateClock ( clock ) {
        clock.innerHTML = new Date().toLocaleTimeString();
    }
    
    setInterval(function () {
        updateClock( clockElement );
    }, 1000);
    
    (function () {
    
      var clockElement = document.getElementById( "clock" );
    
      function updateClock ( clock ) {
        clock.innerHTML = new Date().toLocaleTimeString();
      }
    
      setInterval(function () {
          updateClock( clockElement );
      }, 1000);
    
    }());
    </script>

    You can paste that code in the editor right after your data placeholders. You will want to add the <span id="clock"></span> where you want the clock to appear.

    Those elements can then be styled up if you want by identifying the element ID's and classes then adding some CSS rules.

    In the case of my test, the HTML section had an ID of "html-1" so I styled it up a bit using these rules:

    #html-1 p {
        text-transform: capitalize;
        font-size: 1.5em;
        background: #77;
        color: #fff;
        box-sizing: border-box;
        padding: .2em 1em;
    }

    Screenshot - https://drive.google.com/file/d/1AHf18TkUOhO8fonwfVr1rlPMW4f8ZIBM/view?usp=sharing

    Obviously, you will want to style it up to fit your site's design.

    Try that out and see if it fits your needs.

    Thanks!

    Jeremy

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.