PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Change the output of a users input.

  1. harerace
    Member

    I would like a user to input a number into a TAG field (example - 6147841212) and the output when the forum is posted to the site will be formatted like so (614-784-1212)

    Posted 11 years ago on Friday May 24, 2013 | Permalink
  2. You can do this one of two ways. One way uses built in functionality and if that doesn't meet your needs then you'd have to implement a customization using PHP and available API hooks to customize the behavior.

    To do it with built in functionality you can use what is called an input mask. An input mask uses javascript to force the data being entered into a text input so that it is in the format you define.

    So for example, you could create an input mask that forces the user to enter 10 digits and they'll format like 111-111-1111 or however you define the format.

    In order to do this with an input mask you would use a Single Input field. You would then edit this field and enable the "Input Mask" option. You'll be able to select from some pre-defined input masks or create your own custom one. Since there is no pre-defined mask for what you've described you'd have to create a custom one. It then provides a link that will explain how to define the format.

    Here's a quick screenshot showing an example of a Single Input field with the Input Mask option enabled and the input mask is configured so that the field will allow 10 numeric digits to be entered and it will automatically format them like 999-999-9999: http://db.tt/rusgqBH6

    Now when that form is viewed, that field will enforce the input mask and the user will only be able to input the types of characters, number of characters and the format of those characters you have defined using the input mask. Here is a screenshot showing the input mask I created in the example above (it's the last field on this form): http://db.tt/I9XF1mN0

    Input masks allow you to define what can be entered in the field as well as the format of what is entered in the field.

    If what you want to do cannot be accomplished via an input mask then it would have to be done with custom code. You would need to write a customization that gets the value of the field and transforms it however you need to do so before saving it once again. This can be accomplished using available hooks. Your custom PHP would go in your themes functions.php file.

    Posted 11 years ago on Friday May 24, 2013 | Permalink