Advertisement:

Author Topic: [SOLVED] How to connect an extra field and a default phone field?  (Read 1494 times)

woody

  • Newbie
  • *
  • Posts: 6
Hi there,

I have just created a new custom field PHONE. This will appear for all users on posting form. The problem is that registered users already have their phone field in settings. Is it possible to insert current phone number into my custom phone number field by default if user is logged in and has his phone number in the account settings?
« Last Edit: November 25, 2015, 08:25:18 pm by woody »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to connect an extra field and a default phone field?
« Reply #1 on: November 25, 2015, 01:59:26 pm »
Hi,

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_autofill_user_phone() { ?>


    <script type="text/javascript">   
        var currentPhone = '';
               
        $("#plugin-hook").change(function() {           
            var phoneCFInput = $("#meta_phone"); // If your Custom Field IDENTIFIER is not "phone", change it here ("#meta_IDENTIFIER")

            if (currentPhone == '') {
                phoneCFInput.val('<?php echo osc_user_field('s_phone_land'); ?>');
            } else {
                phoneCFInput.val(currentPhone);
            }

            phoneCFInput.change(function(){
                currentPhone = phoneCFInput.val();
            });
        });
    </script>
<?php }

$section Rewrite::newInstance()->get_section();
if (
$section == 'item_add' || $section == 'item_edit'osc_add_hook('footer''cust_autofill_user_phone');

function 
cust_trigger_plugin_hook() { ?>


    <script type="text/javascript">
        $("#plugin-hook").change();
    </script>
<?php }

osc_add_hook('item_form''cust_trigger_plugin_hook'1);
osc_add_hook('item_edit''cust_trigger_plugin_hook'1);

?>


Mind the line with this comment: "If your custom Field IDENTIFIER is not "phone"..."

This will automatically set the Phone field to the number in the User Profile if exists every time he select another category unless he has expressly changed the Phone number (in this case it will be remembered).

Regards

woody

  • Newbie
  • *
  • Posts: 6
Re: How to connect an extra field and a default phone field?
« Reply #2 on: November 25, 2015, 05:00:27 pm »
I confirm that the solution above works properly for me. Thanks, teseo. Well done  :)

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to connect an extra field and a default phone field?
« Reply #3 on: November 25, 2015, 05:15:43 pm »
You're welcome. :) Please add [SOLVED] to the title of this thread editing the first message, thanks.

Regards

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #4 on: August 09, 2017, 12:40:15 am »
Hello!
Sorry, I'm using an Google translater.
Help please make a mask for the custom field.
I made a mask for s_phone_land

user-profile.php

          <script>
            $(function(){
           $("#s_phone_land").mask("8 (999) 999-99-99");
            });
          </script>
       
I have a custom field of "telephonecustom"

For authorized users a phone is substituted from the field s_phone_land

<?php function cust_autofill_user_phone() { ?>
    <script type="text/javascript">   
        var currentPhone = '';
               
        $("#plugin-hook").change(function() {
            var phoneCFInput = $("#meta_telephonecustom");

            if (currentPhone == '') {
                phoneCFInput.val('<?php echo osc_user_field('s_phone_land'); ?>');
            } else {
                phoneCFInput.val(currentPhone);
            }

            phoneCFInput.change(function(){
                currentPhone = phoneCFInput.val();
            });
        });
    </script>
<?php }

$section = Rewrite::newInstance()->get_section();
if ($section == 'item_add' || $section == 'item_edit') osc_add_hook('footer', 'cust_autofill_user_phone');

function cust_trigger_plugin_hook() { ?>

    <script type="text/javascript">
        $("#plugin-hook").change();
    </script>
<?php }

osc_add_hook('item_form', 'cust_trigger_plugin_hook', 1);
osc_add_hook('item_edit', 'cust_trigger_plugin_hook', 1); ?>

Everything works well!
But I need to add a mask for the "telephonecustom" field, for authorized and unauthorized users.
How to do it?
Help me please!

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #5 on: August 09, 2017, 03:01:43 pm »
Is solved simply
var phoneCFInput = $("#meta_telephonecustom");
Replace
var phoneCFInput = $("#meta_telephonecustom").mask("+7 (999) 999-99-99");

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #6 on: August 10, 2017, 12:21:03 am »
del
« Last Edit: April 29, 2018, 08:23:39 pm by buninsan »

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: How to connect an extra field and a default phone field?
« Reply #7 on: April 29, 2018, 08:24:29 pm »
Hi,

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_autofill_user_phone() { ?>


    <script type="text/javascript">   
        var currentPhone = '';
               
        $("#plugin-hook").change(function() {           
            var phoneCFInput = $("#meta_phone"); // If your Custom Field IDENTIFIER is not "phone", change it here ("#meta_IDENTIFIER")

            if (currentPhone == '') {
                phoneCFInput.val('<?php echo osc_user_field('s_phone_land'); ?>');
            } else {
                phoneCFInput.val(currentPhone);
            }

            phoneCFInput.change(function(){
                currentPhone = phoneCFInput.val();
            });
        });
    </script>
<?php }

$section Rewrite::newInstance()->get_section();
if (
$section == 'item_add' || $section == 'item_edit'osc_add_hook('footer''cust_autofill_user_phone');

function 
cust_trigger_plugin_hook() { ?>


    <script type="text/javascript">
        $("#plugin-hook").change();
    </script>
<?php }

osc_add_hook('item_form''cust_trigger_plugin_hook'1);
osc_add_hook('item_edit''cust_trigger_plugin_hook'1);

?>


Mind the line with this comment: "If your custom Field IDENTIFIER is not "phone"..."

This will automatically set the Phone field to the number in the User Profile if exists every time he select another category unless he has expressly changed the Phone number (in this case it will be remembered).

Regards
There was a task that I have not been able to solve yet.
I ask the community for help.
I created a custom field "zip_code" in order to be able to search for this field.
In the profile, the user has a filled-in "zip" field
        <div class="form-group">
          <label class="control-label"l for="zip">
            <?php _e('Zip code', OSCLASSWIZARDS_THEME_FOLDER); ?>
          </label>
          <div class="controls">
            <?php UserForm::zip_text(osc_user()); ?>
          </div>
        </div>
It is necessary that at the authorized user, the data of a field "zip" were substituted in a field "zip_code" in a file item-post.php.
By analogy with the field cust_autofill_user_phone ()
Thank you in advance for your cooperation!

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #8 on: April 30, 2018, 02:06:01 pm »
Hi,

Assuming that you're already have added the function cust_trigger_plugin_hook() (for telephone), I think this would be it:

Code: [Select]
<?php
function cust_autofill_user_zip() { ?>


    <script type="text/javascript">   
        var currentZip = '';
               
        $("#plugin-hook").change(function() {           
            var zipCFInput = $("#meta_zip_code");

            if (currentZip == '') {
                zipCFInput.val('<?php echo osc_user_field('s_zip'); ?>');
            } else {
                zipCFInput.val(currentZip);
            }

            zipCFInput.change(function(){
                currentZip = zipCFInput.val();
            });
        });
    </script>
<?php }

$section Rewrite::newInstance()->get_section();
if (
$section == 'item_add' || $section == 'item_edit'osc_add_hook('footer''cust_autofill_user_zip');
?>

Regards

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #9 on: April 30, 2018, 08:21:07 pm »
Hi,

Assuming that you're already have added the function cust_trigger_plugin_hook() (for telephone), I think this would be it:

Code: [Select]
<?php
function cust_autofill_user_zip() { ?>


    <script type="text/javascript">   
        var currentZip = '';
               
        $("#plugin-hook").change(function() {           
            var zipCFInput = $("#meta_zip_code");

            if (currentZip == '') {
                zipCFInput.val('<?php echo osc_user_field('s_zip'); ?>');
            } else {
                zipCFInput.val(currentZip);
            }

            zipCFInput.change(function(){
                currentZip = zipCFInput.val();
            });
        });
    </script>
<?php }

$section Rewrite::newInstance()->get_section();
if (
$section == 'item_add' || $section == 'item_edit'osc_add_hook('footer''cust_autofill_user_zip');
?>

Regards

Thank you so much!
Help please translate zip code into upper case.
I can not:(
Here is my code:

function cust_autofill_user_zip() { ?>

    <script type="text/javascript">   
        var currentZip = '';
               
        $("#plugin-hook").change(function() {           
            var zipCFInput = $("#meta_zip_codes").mask("***?* ***");
         $("#meta_zip_codes").val($("#meta_zip_codes").val().toUpperCase());

            if (currentZip == '') {
                zipCFInput.val('<?php echo osc_user_field('s_zip'); ?>');
            } else {
                zipCFInput.val(currentZip);
            }

            zipCFInput.change(function(){
                currentZip = zipCFInput.val();
            });
        });
    </script>
<?php }

$section = Rewrite::newInstance()->get_section();
if ($section == 'item_add' || $section == 'item_edit') osc_add_hook('footer', 'cust_autofill_user_zip');

It is necessary that for unauthorized users the zip code is transferred to the upper case
« Last Edit: April 30, 2018, 09:47:17 pm by buninsan »

Resta

  • Sr. Member
  • ****
  • Posts: 273
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #10 on: May 01, 2018, 03:11:08 am »
Hi,

I think it is getting the zip code from the user information, as is. I don't know - may be this will solve your issue

<?php echo strtoupper(osc_user_field('s_zip')); ?>
« Last Edit: May 01, 2018, 03:18:42 am by Resta »

buninsan

  • Jr. Member
  • **
  • Posts: 96
Re: [SOLVED] How to connect an extra field and a default phone field?
« Reply #11 on: May 18, 2018, 06:40:07 pm »
Hi,

I think it is getting the zip code from the user information, as is. I don't know - may be this will solve your issue

<?php echo strtoupper(osc_user_field('s_zip')); ?>
Thank you!
« Last Edit: May 18, 2018, 06:56:05 pm by buninsan »