Jump to content

Phone Number Fieldtype


adrian

Recommended Posts

Hello @adrian,

I have just upgraded and old site along with this module. So I started to get lots of Unknown column 'field_user_phone.data_country' entries in the log. After seeing all those log entries I came here, just to find this old warning of yours.

On 7/23/2018 at 9:57 PM, adrian said:

FYI - I just merged the 3.0 branch to master - be warned that this is a breaking change because of the new data_country db field so please don't update existing installs unless you're prepared to do some DB manipulation - if you want to and can't figure out the required SQL commands, let me know and I can post something here.

If I'm not mistaken, I should now update the database manually, but how?

Could you please help me out?

Link to comment
Share on other sites

  • 6 months later...

Hi @szabesz - sorry for such a late reply, but this should show what needs to change: https://github.com/adrianbj/FieldtypePhone/commit/b3376e13615a702bf5075f94c08e790ab9778c53

I added a new data_country field and moved the contents of the data field to data_country and then populated data with the raw number (concatenate data_country and data_number).

Hope that helps still.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hi @adrian, your phone field just came right in time, so I gave it a try and it fits my needs well. I now want to use this fieldtype InputfieldPhone in a custom form delivered by my module. After several tries and fails I found a way, but it feels a bit odd. Is there a better/right way to use a predefined/configured field in a custom form? I guess this question is not related to your field… more a general one – but as I was stumbling across that need with the phone field I post my question here (…and because I really value your experience).

// module context
public function ___executeTest() {

    $modules = $this->wire()->modules;

    $fields = $this->wire()->fields;
    $phone = $fields->get('m_phone_2');
    
    $p = New Page;						//is that the right way to do it?
    $input = $phone->getInputfield($p);
    

    /** @var InputfieldForm $form */
    $form = $modules->get('InputfieldForm');
    $form->attr('id', 'PhoneTest');

    $form->append($input);

    // $wrapper = new InputfieldWrapper();
    // $wrapper->add($input);
    // $form->append($wrapper);

    $out = $form->render();
    return $out;

  }

Thank you!

15 minutes later – addendum: in my usecase, a new user is created on submit. In $form->process() I fetch the data and try to set the values to a new user:

//$form->process()
    //add new user
    $newuser = new User();
    $newuser->name = $form->getValueByName('name');
    // … other fields

    $newuser->m_phone_2 = $form->getValueByName('m_phone_2');	// is formatted value here +49 (0)### #######

	$newuser->save();

I now have to fetch the values from the raw post data:

$data = $this->wire('input')->post;

$newuser->m_phone_2->set('country', $data->m_phone_2_country;);
$newuser->m_phone_2->set('area_code', $data->m_phone_2_area_code);

again I just wonder… is this the way to go?

2024-02-24_17-53-21.png

Link to comment
Share on other sites

  • 1 month later...

Hello @adrian,

thank you for this module. I am using it on one of our websites and get following warning with PHP 8.2.0 in TracyDebugger:

Quote

PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in .../site/modules/FieldtypePhone/FieldtypePhone.module.php:330

Could you please update your module to remove this warning? 🙂

Regards, Andreas

Link to comment
Share on other sites

Hi @AndZyk - it seems like you have an empty "Phone Output Format Options" field in the module's config settings.

By default, it is populated with the following, so you can paste this in, or build your own format. Does that fix things for you?

/*North America without separate area code*/
northAmericaStandardNoSeparateAreaCode | {+[phoneCountry]} {([phoneNumber,0,3])} {[phoneNumber,3,3]}-{[phoneNumber,6,4]} {x[phoneExtension]} | 1,,2215673456,123
northAmericaStandardNoSeparateAreaCodeNoNumberDashes | {+[phoneCountry]} {([phoneNumber,0,3])} {[phoneNumber,3,7]} {x[phoneExtension]} | 1,,2215673456,123
northAmericaStandardNoSeparateAreaAllDashes | {+[phoneCountry]}-{[phoneNumber,0,3]}-{[phoneNumber,3,3]}-{[phoneNumber,6,4]} {x[phoneExtension]} | 1,,2215673456,123
northAmericaStandardNoSeparateAreaDashesNoNumberDashes | {+[phoneCountry]}-{[phoneNumber]} {x[phoneExtension]} | 1,,2215673456,123

/*North America with separate area code*/
northAmericaStandard | {+[phoneCountry]} {([phoneAreaCode])} {[phoneNumber,0,3]}-{[phoneNumber,3,4]} {x[phoneExtension]} | 1,221,5673456,123
northAmericaNoNumberDashes | {+[phoneCountry]} {([phoneAreaCode])} {[phoneNumber]} {x[phoneExtension]} | 1,221,5673456,123
northAmericaAllDashes| {+[phoneCountry]}-{[phoneAreaCode]}-{[phoneNumber,0,3]}-{[phoneNumber,3,4]} {x[phoneExtension]} | 1,221,5673456,123
northAmericaDashesNoNumberDashes | {+[phoneCountry]}-{[phoneAreaCode]}-{[phoneNumber]} {x[phoneExtension]} | 1,221,5673456,123

/*Australia*/
australiaNoCountryAreaCodeLeadingZero | {([phoneAreaCode,0,2])} {[phoneNumber,0,4]} {[phoneNumber,4,4]} {x[phoneExtension]} | 61,07,45673456,123
australiaWithCountryAreaCodeNoLeadingZero | {+[phoneCountry]} {([phoneAreaCode,1,1])} {[phoneNumber,0,4]} {[phoneNumber,4,4]} {x[phoneExtension]} | 61,07,45673456,123

 

  • Like 1
Link to comment
Share on other sites

Hi @adrian, thanks you for your response.

You are right. When I developed the website I wanted a special phone number format, so I choose under Phone Output Format "None" and build my own format like this:

<a href="tel:<?=$person->phone->unformattedNumberNoExt?>">
    <?php if ($person->phone->area_code) { echo $person->phone->area_code; } else { echo "07723"; } ?>
    <?php if ($person->phone->number) echo "/{$person->phone->number}"; ?>
    <?php if ($person->phone->extension) echo "-{$person->phone->extension}"; ?>
</a>

Probably because I didn't understand the syntax of the Phone Output Format at the time. 😊

If you have to choose a Phone Output format, wouldn't it be better to remove the option "None"?

Link to comment
Share on other sites

Hi @AndZyk - you don't need to select an output format - none is perfectly valid (it's basically "unformatted").

That said, I have fixed the error if for some reason you decide to empty the options textarea.

PS - it's worth figuring out the syntax- I know it looks a bit overwhelming at first, but it's really powerful and keeps your template code much cleaner.

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, AndZyk said:

Just FYI I had selected None and had the default values in the options textarea of the module settings.

Weird - maybe you had just never saved the settings so the format wasn't available? Anyway, shouldn't matter now regardless.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...