Osclass forums
Support forums => old => Topic started by: woody on November 24, 2015, 01:20:01 am
-
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?
-
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.
<?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
-
I confirm that the solution above works properly for me. Thanks, teseo. Well done :)
-
You're welcome. :) Please add [SOLVED] to the title of this thread editing the first message, thanks.
Regards
-
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!
-
Is solved simply
var phoneCFInput = $("#meta_telephonecustom");
Replace
var phoneCFInput = $("#meta_telephonecustom").mask("+7 (999) 999-99-99");
-
del
-
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.
<?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!
-
Hi,
Assuming that you're already have added the function cust_trigger_plugin_hook() (for telephone), I think this would be it:
<?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
-
Hi,
Assuming that you're already have added the function cust_trigger_plugin_hook() (for telephone), I think this would be it:
<?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
-
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')); ?>
-
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!