Jump to content

Recommended Posts

Posted

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?

  • 6 months later...
Posted
12 hours ago, adrian said:

Hope that helps still.

Thanks Adrian! I simply postponed upgrading the module. Next time I work on that site, I will surely try to upgrade it base on the info you provided above.

  • 1 year later...
Posted

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

  • 1 month later...
Posted

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

Posted

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
Posted

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"?

Posted

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
Posted

Thank you, next time I will try to use the format options. ☺️

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

Regards, Andreas

 

Posted
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
  • 5 months later...
Posted

Hello Adrian,
Just a quick question. I have set output to NorthAmericaDashes. I was wondering if I can set input to fit the output. I use the fieldtype in my FormBuilder and user complains that they don't know the format to use since it's not as usual. They want 123-4567 but we have to enter 1234567 to avoid errors. Is it possible to do that?
Thanks again!

  • 2 weeks later...
Posted

@mel47 - Did you consider using the option to have separate area code and number fields which I think would avoid that confusion. If you don't want that option, I think I could pretty easily have any option to allow dashes and parentheses but automatically strip them when saving to the database. Would that work ok for you?

Posted

I already have area and number separated. My issue is about the number only. We have to type without dashes, but since no one is normally doing that, some confusion arises and they always have an error (and they need to remove the dash they typed to get a valid answer). So yes, if the dash could be strip somehow, it will be ideal!
 

Posted

@mel47 - please test the attached version.

There is a new option (on the Input tab of the field) for "Allow formatting characters in Input, eg. - ( ."

Note that unlike the "Letters" option, the formatting characters will be stripped before saving to the DB.

FieldtypePhone.zip

  • Thanks 1

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...