Jump to content
adrian

Phone Number Fieldtype

Recommended Posts

@Roman Schmitz - just wanted to let you know that I have committed a new version to Github that fixes your issue, as well as updates the module in several ways for newer PW versions.

Please let me know if you have any problems with the new version.

  • Like 3

Share this post


Link to post
Share on other sites
1 minute ago, Roman Schmitz said:

I have changed the line and now everything works as expected.

 

Please see my second post - I have updated the module with that fix (actually done differently), as well as some other improvements / updates. I would recommend grabbing the latest version of the module.

Cheers,
Adrian

  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, adrian said:

Please see my second post - I have updated the module with that fix (actually done differently), as well as some other improvements / updates. I would recommend grabbing the latest version of the module.

Cheers,
Adrian

I missed the second post. Now I have the new version installed and everything works great.

Thanks again for the quick response.

  • Like 2

Share this post


Link to post
Share on other sites

Hi Adrian,

I'm having some issues getting the proper output formatting with PW 3.0.61 and the following custom format option:

{[phoneAreaCode]-}{[phoneNumber,0,3]-}{[phoneNumber,4,4]} /* Local North America: 111-111-1111 */

The dropdown outputs my example numbers correctly (555-555-5555), both the module and my phone-based field show the correct format chosen, and on the data entry side, I'm getting Area Code and Number fields in the same box which makes sense. However, when I go to output this field on the front end...

/* imagine the entered data is 416 7773333 and the desired output is 416-777-3333 */

echo $user->cell_phone; /* returns 7773333 */
echo $user->cell_phone->formattedNumber; /* returns nothing, as does the 'un' variant */
echo $user->cell_phone->area_code.$user->cell_phone->number; /* returns 4167773333 */

I could string manipulate the last into what I need, but that would seem to defeat the purpose of the module. Is this only intended to work with $page based references?

Share this post


Link to post
Share on other sites

Hi @Arcturus - sorry for such a delayed response - I am just back from an extended time away from my computer.

I can't imagine why it's not working for you, unless you are entering the entire "416 7773333" in the main number sub field. The 416 area code needs to be entered in the area code subfield.

Could you please confirm how you are entering things and also the settings for the "cell_phone" field with some screenshots so I can help you diagnose?

Share this post


Link to post
Share on other sites

No worries Adrian, I'll see if I can circle back to that project and investigate next week.

Share this post


Link to post
Share on other sites

Hi,

Does someone solve or found a work-around for problematic error when used in FormBuilder?

Thanks

image.png.980f9ad3937c791d0622ba67249db2c0.png

Share this post


Link to post
Share on other sites

Hi @mel47 - thanks for raising the issue here, but let's continue it in the FormBuilder thread where we will get more of Ryan's input

 

Share this post


Link to post
Share on other sites

Thanks for the module!

Is there a way to set the contents of this field via the processwire api?
I'd like to import a large chunk of contacts and I'm using this fieldtype to store the phone numbers.

Thanks!

Share this post


Link to post
Share on other sites
16 hours ago, Torsten Baldes said:

Is there a way to set the contents of this field via the processwire api?
I'd like to import a large chunk of contacts and I'm using this fieldtype to store the phone numbers.

Of course:

$page->of(false);
$page->phone->country = '1';
$page->phone->area_code = '123';
$page->phone->number = '4567890';
$page->phone->extension = '987';
$page->save('phone');

 

Share this post


Link to post
Share on other sites

Hello Adrian,

I want to use the shortcut syntax $page->fieldname->formattedNumber on a file outside of the template folder (in my case a simple template which will be loaded via an Ajax call). But this  doesnt work!

In opposition $page->fieldname as standalone works. So the formatting object "formattedNumber" is not callable outside of the template folder. The file where I want to use it is located in /site/ajax/nameofthefile.php (outside of the template folder). I use the bootstrapping technique to get field values outside of PW templates folder.

Is there a possiblility to load the module inside this template file so I can use formatted and unformatted numbers?

Best regards

Share this post


Link to post
Share on other sites

Hi @Juergen - it's all about output formatting. It is off by default when bootstrapping.

So just do this:

$p = $pages->get(n);
$p->of(true);
$p->fieldname->formattedNumber // OR $p->fieldname

Remember that calling $p->fieldname will actually return a formatted version by default - you don't need to explicitly specify ->formattedNumber

If you don't want to turn on output formatting for the entire response, you can also use PW's getFormatted like this:

$p->getFormatted('fieldname');

 

  • Like 2

Share this post


Link to post
Share on other sites

@mel47 - I just committed the version that supports FormBuilder so you can now start using this version again.

Share this post


Link to post
Share on other sites
8 hours ago, adrian said:

It is off by default when bootstrapping

Thank you. I didnt know this. Now it works :)

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian,

I got an error on line #186 in InputfieldPhone.module. Error comes up on a created phone field.

Fixed it by using double underscore. Wrote an issue in github, too.

Error (with single underscore):

$f->description = _('Whether to ask for extension when entering phone numbers.', __FILE__);

Fix (double underscore):

$f->description = __('Whether to ask for extension when entering phone numbers.', __FILE__);

 

I got two other issues, too, but can't figure it out how that works: The phone field is in a user template called "person" (have multiple user templates), and if I set a zero at the beginning of the area code, then this zero will not be saved, as long as I write another number to it (after or before the zero). Here some examples:

  • Number 123 -> change to 0123 -> after save: 123
  • Number 123 -> change to 01123 -> after save: 01123 -> change to 0123 -> after save: 01123
  • Number 0123 -> change to 00123 -> after save: 0123
  • Number 0123 -> change to 10123 -> after save: 10123
  • Number 123 -> change to 0456 -> after save: 0456 -> change to 0123 -> after save: 0123

Best solution for now is to delete the field and set it new.  Anther Solution is to change the numbers to something else then change it back.

The output on the frontend wasn't changed after the profile update, I had to save/update(select output format) the phone field again, so the output was right again. That was no caching problem, or at least no normal one.

Edited by godmok
added two additional issues
  • Like 1

Share this post


Link to post
Share on other sites

Thanks for those reports @godmok - should all be fixed in the latest version, although I didn't quite understand

5 hours ago, godmok said:

The output on the frontend wasn't changed after the profile update

so could you please check that is working now as well. I assume it was related to the leading zero issue which is now fixed.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian, sorry for being late. Now the field works like it should.

I was just questioning myself if it would be possible to create own formated numbers and output them. I use something like this on the field input: 49 0123 456 789. On the output I remove the zero from 0123 if there is one. Then in the frontend there is a link with "tel:+" and I can't use the unformatted number, because the number is wrong. Output unformatted output: 490123456789. This should be the own created output format: 49123456789. Best would be formated as +49123456789.

In the field settings I have set the format with removing the first number, but how can I get this self made output format easy into the frontend? I have created a function for that, but it would be nice to have individual output format names like: $phone->fomatedNumberNoAreaLeadingZero (fomatedNumberNoAreaLeadingZero would be my own set name in the settings, as example), and the output will be from the settings.

Would be nice :)

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, godmok said:

I was just questioning myself if it would be possible to create own formated numbers and output them.

In the module settings you can create your own format. Take a look at the Australia examples - the one with the country code has no leading zero for the area code. My initial suggestion to you would be to create your format based on that. I guess the contingency I never implemented is when you want to be able to call different formats for the same phone field.

My initial thought for adding this is to allow you to call the format based on the name of the format in the commented part. So for example if you created a format like this:

+1 (23) 456-7890 x321 /* My No Leading Zero With Country: +1 (11) 111-1111 x111 */

you would be able to call it via the API like this:

$page->phone->formatted('MyNoLeadingZeroWithCountry');

That way you could create whatever custom formats you need, name them how you want, and call multiple versions on the same field because these wouldn't rely on the format chosen either in the module settings or the field settings.

Does this sound ok?

  • Like 2

Share this post


Link to post
Share on other sites

Sounds good for me :) Would definitely use it like this!

I tested the field again and changed the fieldtype settings for the "Phone Output Format" under "Modules" -> "FieldtypePhone" and see there, again problems came up.

This are my Output Format Options:

{+[phoneCountry] }{([phoneAreaCode]) }{[phoneNumber,0,3]-}{[phoneNumber,3,4]}{ x[phoneExtension]} /* Standard North America: +1 (111) 111-1111 x111 */
{+[phoneCountry] }{([phoneAreaCode]) }{[phoneNumber]}{ x[phoneExtension]} /* Alternate North America: +1 (111) 1111111 x111 */
{+[phoneCountry]-}{[phoneAreaCode]-}{[phoneNumber,0,3]-}{[phoneNumber,3,4]}{ x[phoneExtension]} /* Alternate North America: +1-111-111-1111 x111 */
{+[phoneCountry]-}{[phoneAreaCode]-}{[phoneNumber]}{ x[phoneExtension]} /* Alternate North America: +1-111-1111111 x111 */
{([phoneAreaCode,0,2]) }{[phoneNumber,0,4] }{ [phoneNumber,4,4]}{ x[phoneExtension]} /* Standard Australia without country code and with leading zero for area code: (01) 1111 1111 x111 */
{+[phoneCountry] }{([phoneAreaCode,1,1]) }{[phoneNumber,0,4] }{ [phoneNumber,4,4]}{ x[phoneExtension]} /* International Australia with country code and without leading zero for area code: +1 (1) 1111 1111 x111 */

{+[phoneCountry] }{([phoneAreaCode,1,6]) }{[phoneNumber,0,3] }{ [phoneNumber,3,3]}{ [phoneNumber,6,3]}{ [phoneNumber,9,3]}{ - [phoneExtension]} /* International phone number with country code and without leading zero for area code: +49 (111) 123 456 789 012 - 111 */

I have set a line between your examples and mine (last line). I can select the format without a problem, but:

  • If I delete the line break between, then the selection will not change but has as first option "none" (normally there would be the unformatted version). I would suggest to ignore such empty line breaks in the Format Options textarea, but still have the possibility to set them for groups.
  • If I change let's say "phoneNumber,9,3" to "phoneNumber,9,2" in my code (with or without line break), then my format selection is lost and set to unformatted (or "none" as it is first option). Additionally any change in the Format Options field has changed the created field under "Setup" -> "Fields", and there it is set to unformatted/first option. It happens with any changes on the options (adding/removing a block and so on). As I see the <option value=""> under "Fields" uses the Format Option as the value but then loses it after a change.
    And: the frontpage output is still on the last Output Format Option, means no changes were updated on the frontend at all. It won't change as long as I save the field under "Fields" again with the right Format Option selected. That is OK, but then you have to know that you have to update all fields with this selected option again :/

Hope this helps somehow...

Share this post


Link to post
Share on other sites

@godmok - obviously an easy fix to ignore blank lines. The issue of the format not being updated is a little trickier - currently the selected format is stored by the format "code", rather than by a name, so changing the definition of a format won't update the format stored for a field. I should probably store formats by their "name" so the current definition for a format is called each time. I think this would be a good improvement for this module and would also be inline with your request to be able to call the format directly. The catch is making sure I don't break existing sites using this module, so I'll have to make this change with that in mind.

I'll see what I can do.

  • Like 1

Share this post


Link to post
Share on other sites
48 minutes ago, adrian said:

I'll see what I can do.

I am about to use this module too (for the first time). The discussed improvements do sound good. Thanks in advance, Adrien!

Share this post


Link to post
Share on other sites

@godmok and @szabesz - well that took way too much time :)

It's very rough, but please test the new version on the dev branch: https://github.com/adrianbj/FieldtypePhone/tree/dev

This new version has lots of breaking changes, so please don't update an existing site. You'll need to uninstall and reinstall to get the new format for the default formats to show. You could I guess copy/paste them in from the module code to that field if you have data already that you can't lose.

Format options now have a proper name associated with them, so if you change the pattern for a format, it should update the output everywhere. Also, you can now see exactly how each format will look based on the pattern, rather than you having to enter that in a comment at the end.

image.png.2b1267bd5199c326b24d20d9b5722682.png

 

When defining formats, follow this format. The category headings are optional. The key things is: name | pattern

image.thumb.png.527ccf9e0b3a70d1a5ba45af6acc5f68.png

Now you can also call these formats separately from the API regardless of what the selected output format is. You can call like this:

$page->phone->australiaWithCountryAreaCodeNoLeadingZero

 

  • Like 3

Share this post


Link to post
Share on other sites

This works! tried it on a development site and will now install the new version of it to live.

Update: worked on live site without problems after updating Phone Format Output and my phone field in admin and template file.

  • Like 1

Share this post


Link to post
Share on other sites

@godmok, @szabesz and @mel47 - could you please try the latest version on the dev branch. I had to rejig a few things to get this new version to also work with Form Builder.

@mel47 - please read my previous post above regarding the breaking changes in this new version. I'll be making this the master version once I have confirmation from you guys that you aren't seeing any problems. I don't like introducing breaking changes, but in this case it was necessary to allow more flexibility for calling custom outputs via the API.

Thanks!

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2020-01-14 --> new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 --> orders filter, order details, download + resend invoices, refunds 2019-10-18 --> list filters, REST API improvements, new docs platform, and more ... 2019-08-08 --> dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 --> taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 --> FieldtypeSnipWireTaxSelector 2019-05-25 --> SnipWire will be free and open source If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      Please have a look at the screenshots to get an idea what I'm talking about (open spoiler):
      (Please note: these screenshots are from an early development state of SnipWire. To see actual screens please have a look at later posts below!)
       
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.60
      Composer: rockett/jumplinks
      ⚠️ NOTICE: 1.5.60 is an important security patch-release for an XSS vulnerability discovered by @phlp. It's HIGHLY RECOMMENDED that all Jumplinks users update to the latest version as soon as possible.
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! 🙂
    • By Robin S
      Add Image URLs
      Allows images/files to be added to Image/File fields by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image and file fields. Use the button to show a textarea where URLs may be pasted, one per line. Images/files are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
      https://modules.processwire.com/modules/add-image-urls/
×
×
  • Create New...