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

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