Skip to content

Commit

Permalink
Support for FormBuilder. ReadMe cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbj committed Jan 14, 2018
1 parent ca5142e commit bc87e50
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.module linguist-language=PHP
2 changes: 1 addition & 1 deletion FieldtypePhone.module
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FieldtypePhone extends Fieldtype implements Module, ConfigurableModule {
return array(
'title' => __('Phone', __FILE__), // Module Title
'summary' => __('Multi part phone field, with custom output formatting options.', __FILE__), // Module Summary
'version' => '1.2.0',
'version' => '1.2.1',
'author' => 'Adrian Jones',
'href' => 'http://modules.processwire.com/modules/fieldtype-phone/',
'installs' => 'InputfieldPhone',
Expand Down
Empty file modified InputfieldPhone.css
100755 → 100644
Empty file.
12 changes: 8 additions & 4 deletions InputfieldPhone.module
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InputfieldPhone extends Inputfield {
return array(
'title' => __('Phone Inputfield', __FILE__), // Module Title
'summary' => __('Multi part phone field, with custom output formatting options.', __FILE__), // Module Summary
'version' => '1.2.0',
'version' => '1.2.1',
'author' => 'Adrian Jones',
'href' => 'http://modules.processwire.com/modules/fieldtype-phone/',
'icon' => 'phone',
Expand Down Expand Up @@ -69,7 +69,7 @@ class InputfieldPhone extends Inputfield {

$out = '';

$value = $this->attr('value') ? $this->attr('value') : new Phone();
$value = $this->attr('value') ? $this->attr('value') : new \Phone();

if($this->input_country == 1){
$out .= "<div class='phone_col'>";
Expand Down Expand Up @@ -125,6 +125,8 @@ class InputfieldPhone extends Inputfield {
$name = $this->attr('name');
$value = $this->attr('value');

if(is_null($value)) $value = new \Phone;

$pn_names = array(
'country' => $name . "_country",
'area_code' => $name . "_area_code",
Expand All @@ -142,13 +144,15 @@ class InputfieldPhone extends Inputfield {
$this->wire()->error($this->_("Field only accepts numeric values"));
} else {
$value->set($key, $this->wire('sanitizer')->digits($input->$name));
$this->trackChange('value');
}

}
}
}

if($value != $this->attr('value')) {
$this->trackChange('value');
$this->setAttribute('value', FieldtypePhone::formatPhone($value->country, $value->area_code, $value->number, $value->extension, $this->output_format));
}
return $this;
}

Expand Down
Empty file modified LICENSE
100755 → 100644
Empty file.
41 changes: 13 additions & 28 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Phone Number Fieldtype
======================
# Phone Number Fieldtype

A new fieldtype to enter phone numbers with 4 integer values for country, area code, number and extension and format the output based on predefined or custom options.
A ProcessWire fieldtype to enter phone numbers with 4 integer values for country, area code, number and extension and format the output based on predefined or custom options.

##StyledOutput
## StyledOutput

The most common usage option will be:
```
Expand Down Expand Up @@ -31,7 +30,7 @@ echo $page->fieldname->unformattedNumberNoCtryNoExt: //eg. 1234567890
Of course the actual output is determined by the selected format output


##Raw Output
## Raw Output

You can output the values for the component parts of the phone number like this:
```
Expand All @@ -41,21 +40,21 @@ echo $page->fieldname->number;
echo $page->fieldname->extension;
```

##Output for mobile compatibility
## Output for mobile compatibility

To get iOS and other mobile platforms to recognize numbers and be able to automatically dial them, use something like this:
```
echo '<a href="tel:+'.$page->fieldname->unformattedNumberNoExt.'">'.$page->fieldname->formattedNumber.'</a>';
```

##Selectors for searching
## Selectors for searching

The component parts can be used in selectors like this:
```
$pages->find("phone.area_code=123");
```

##Field Settings
## Field Settings

There is a field settings for the width of the inputs in pixels.

Expand All @@ -64,7 +63,7 @@ You can also choose whether to display the country and extension fields for inpu
There is an additional checkbox that determines whether there is an option to override the default format option on a per entry basis, which will be useful when styling phone numbers from different countries on the one website. Off by default.


##Custom formatting options
## Custom formatting options

On the module's configuration page you can choose from predefined formats, or create custom formats using syntax like this:
```
Expand All @@ -88,36 +87,22 @@ There are lots of complicated rules around numbers changing when dialed from dif
which generates: +1 (7) 1234 5678 x123 even though the full "07" is stored in the area code field.


##Where to get
## Setup

Available from github:
https://github.com/adrianbj/FieldtypePhone
* Choose a Phone Output Format from the module's configuration page. You can also set the numbers that will be used in the formatted example which may be helpful in certain regions to give a more realistic example.
* Create a new Field with the new "Phone" Fieldtype.

And the modules directory:
http://modules.processwire.com/modules/fieldtype-phone/

## Support

##Support
http://processwire.com/talk/topic/4388-phone-number-fieldtype/


##To Do
## To Do

Need to increase the number of pre-defined formats. There seem to be so many options and no real standards, so I thought rather than create a huge list of options that no-one will use, I thought I'd wait and get you guys to contribute them as you need them. Either post your formats here, or send me a PR on github and I'll add them.


##How to install

Download and place the module folder named "FieldtypePhone" in: /site/modules/

In the admin control panel, go to Modules. At the bottom of the screen, click the "Check for New Modules" button.

Now scroll to the FieldtypePhone module and click "Install". The required InputfieldPhone will get installed automatically.

Choose a Phone Output Format from the module's configuration page. You can also set the numbers that will be used in the formatted example which may be helpful in certain regions to give a more realistic example.

Create a new Field with the new "Phone" Fieldtype.

##Acknowledgments

This module uses code from Soma's DimensionFieldtype and the core FieldtypeDatetime module - thanks guys for making it so easy.
Expand Down

0 comments on commit bc87e50

Please sign in to comment.