buddypress hide profile fields - buddypress

I know there is a method in BuddyPress which can help to hide some profile fields:
function bp_has_profile( $args = '' ) {
global $profile_template;
// Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page,
// or this is a registration page
$hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() );
// We only need to fetch visibility levels when viewing your own profile
if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) {
$fetch_visibility_level_default = true;
} else {
$fetch_visibility_level_default = false;
}
$defaults = array(
'user_id' => bp_displayed_user_id(),
'profile_group_id' => false,
'hide_empty_groups' => true,
'hide_empty_fields' => $hide_empty_fields_default,
'fetch_fields' => true,
'fetch_field_data' => true,
'fetch_visibility_level' => $fetch_visibility_level_default,
'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude
'exclude_fields' => false // Comma-separated list of profile field IDs to exclude
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level );
return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
}
I am not sure how to call this method and pass 'exclude_fields' => $IDs_to_hide

Yes, It is possible to hide some fields from the profile page.
First go to the edit.php in your theme folder.Here if you want to hide the text box and name is "Full Name".
<?php if ( 'textbox' == bp_get_the_profile_field_type() ) : ?>
<?php if ( 'Full Name' != bp_the_profile_field_name() ) : ?>
<label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
<input type="text" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" value="<?php bp_the_profile_field_edit_value(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
<?php endif; ?>
<?php endif; ?>
The above code is same as in profile.php file but I will put only the new if condition same as put the condition in other Radiobutton and Selectbox etc.
Your Full Name profile field are not displayed in your profile.

Not sure if there is a way to do this with your theme functions, but you can easily hide it in the edit loop. Copy /buddypress/members/single/profile/edit.php to your theme and add this line:
<?php if ( 'Field Name' == bp_get_the_profile_field_name() ) continue; ?>
Just below this line:
<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
This is similar to Chirag's approach, but will skip all things related to the field including the wrapper div, so you don't have extraneous HTML.

You can use CSS to hide specific fields with id selector.
#field_1 {
display:none;
}
#signup_username {
display:none;
}

You can do it via bp_before_has_profile_parse_args filter:
function skip_xprofile_fields( $args ){
global $bp, $wpdb;
$field_name = 'First Name';
$field_id = $wpdb->get_var( "SELECT id FROM {$bp->profile->table_name_fields} WHERE `name` = '".esc_sql($field_name)."'");
$args['exclude_fields'] = ','.$field_id;
return $args;
}
add_filter('bp_before_has_profile_parse_args', 'skip_xprofile_fields' );
Just replace $field_name var with your field name.

Related

yii dependent dropdown is not working

This is my view page
<?php echo $form->dropDownListRow($order,'area_id',Area::model()->getActiveAreaList(),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('currentController/getdeliveryforarea'),
'update'=>'#pickup_time_slot', //selector to update
'data' => array('area_id' => 'js:this.value',),
)));
?>
<?php echo $form->dropDownListRow($order,'pickup_time_slot',array(),array('prompt'=>'Select time')); ?>
and in my controll the getdeliveryforarea is like
public function actionGetdeliveryforarea()
{
$data=Areatimeslot::model()->findAll('area_id=:area_id',
array(':area_id'=>(int) $_POST['id']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
here my dependent dropdown is not working ,from getActiveAreaList i will get the area list in first dropdown and once i choose an area it must show corrosponding time list in second dropdown,i hope someone will help me out,thanks in advance
Use Juqery migrate plugin or try something like,
jQuery.browser = {};
(function () {
jQuery.browser.msie = false;
jQuery.browser.version = 0;
if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
jQuery.browser.msie = true;
jQuery.browser.version = RegExp.$1;
}
})();

yii2 Dimensions to be validated and display the error message in the form

In yii2 project I have my own file structure setup. Anything uploaded will get saved as a file type. I can get the file dimensions using the file uploaded in the temp folder by yii2. Using those dimensions I set my own width and height and compare them. If the height and width is more than what I have declared It has display an error message in the form. Which I am unable to do it.
My Active Form
<div class="company-form">
<?php
$form = ActiveForm::begin([
'action'=>['company/logo', 'id'=>$model->company_id],
'validateOnSubmit' => true,
'options' =>
['enctype' => 'multipart/form-data','class' => 'disable-submit-buttons','id'=> 'companyLogoForm'],
'fieldConfig' => [
'template' => "<div class=\"row\">
<div class=\"col-xs-6 margin-top-8\">{label}</div>\n<div class=\"col-xs-6 text-right\">{hint}</div>
\n<div class=\"col-xs-12 \">{input}</div>
</div>",
],
]); ?>
<?= $form->errorSummary($model, $options = ['header'=>'','class'=>'pull-left']); ?>
<?= $form->field($model, 'company_name')->hiddenInput(['maxlength' => true])->label(false) ?>
<?= $form->field($file, 'file')->fileInput([])->label(Yii::t('app', 'Attach Logo'),['class'=> 'margin-top-8']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Save') : Yii::t('app', 'Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary','data' => ['disabled-text' => 'Please Wait']]) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
My Controller Action
public function actionLogo($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$file = new File;
$file->load(Yii::$app->request->post());
$a = UploadedFile::getInstance($file,'file');
$size = getimagesize($a->tempName);
$maxWidth = 500;
$maxHeight = 500;
if ($size[0] > $maxWidth || $size[1] > $maxHeight)
{
$model->addError('file', $error = 'Error Message');
if($model->hasErrors()){
return ActiveForm::validate($model);
}
}
$file->file = UploadedFile::getInstance($file,'file');
$file->file_name = $file->file->name;
$file->file_user = Yii::$app->user->id;
$file->file_type = 1;
if($file->save()){
$file->file_path = Files::getFilePath($file->file_id);
$validDir = $file->file->createFileDir($file->file_path, $file->file_id);
if($validDir){
$file->file->saveAs($file->file_path, false);
if($file->save()){
$model->company_file = $file->file_id;
$model->save();
return $this->redirect(['index']);
}
}
}
}
}
How do I add error message in the controller and pass that to display on my form on the modal box.
Note: my form is displayed on the modal box.
Thank you!!
You should handle the file processing in your model - or even better, create a specific UploadForm model for this purpose.
In that case you can use File Validation or a custom validator to set errors during model validation.
The built-in yii\validators\FileValidator gives you plenty pf validation rules out of the box.
This is actually pretty well explained in the documentation: Uploading Files
See also the documentation for FileValidator
Example for validating an uploaded image file:
namespace app\models;
use yii\base\Model;
use yii\web\UploadedFile;
class UploadForm extends Model
{
/**
* #var UploadedFile
*/
public $imageFile;
public function rules()
{
return [
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
];
}
public function upload()
{
if ($this->validate()) {
$this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
}
Try this validation rule
['imageFile', 'image', 'minWidth' => 250, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250, 'extensions' => 'jpg, gif, png', 'maxSize' => 1024 * 1024 * 2],

Yii CJuiAutoComplete widget: event of empty response message

If the response does not contain data about the city, I want to see the output message. Also i want to change css of text in textfield when I get an empty response.
I have:
View:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'city_id',
'value'=>'',
'source'=>CController::createUrl('/PromouterCity/autoComplete'),
'options'=>array(
'showAnim'=>'fold',
'minLength'=>'0',
'select'=>'js:function( event, ui ) {
$("#city_id").val( ui.item.name );
$("#selectedvalue").val( ui.item.id);
return false;
}',
),
'placeholder' => "Search...",
),
));
Controller:
public function actionAutoComplete(){
$match=$_GET['term'];
if(!empty($match)){
$match = addcslashes($match, '%_');
$q = new CDbCriteria( array(
'condition' => "name LIKE :match",
'params' => array(':match' => "$match%")
));
$query = City::model()->findAll($q);
}else{
$query=array(
'0'=>array(
'id'=>'1',
'name'=>'London',
)
);
}
$list = array();
foreach($query as $q){
$data['label']=$q['name'];
$data['id']= $q['id'];
$data['name']= $q['name'];
$list[]= $data;
unset($data);
}
echo CJSON::encode($list);
Yii::app()->end();
}
Decision:
'response'=> 'js:function( event, ui ) {
if (ui.content.length === 0) {
$("#empty-message").text("your message");
} else {
$("#empty-message").empty();
}
}',

How can you call a CJuiDialog in beforesave

I will appreciate if somebody could help me to find how to solve out one problem, I have a checkbox in my create form. If i pushed the create button I want to have a popup window if the checkbox is checked and do nothing if the checkbox is unchecked.
my codes in _form
<?php echo $form->checkBoxRow($model, 'default'); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
in my create controller
public function actionCreate()
{
$model=new EmpSched;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['EmpSched']))
{
$model->attributes=$_POST['EmpSched'];
if($model->save())
$this->redirect(array('view','id'=>$model->id_empsched));
}
$this->render('create',array(
'model'=>$model,
'emp'=> new CActiveDataProvider('schedule'),
));
}
in my create.php
<?php
$this->breadcrumbs=array(
'Emp Scheds'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List EmpSched','url'=>array('index')),
array('label'=>'Manage EmpSched','url'=>array('admin')),
);
?>
<h1>Create EmpSched</h1>
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'schedule-grid',
'dataProvider'=>$emp,
'columns'=>array(
'id_sched',
'sched_name',
array(
'name'=>'mon',
'value'=>'$data->fkidday->monday->name'
),
array(
'name'=>'tues',
'value'=>'$data->fkidday->tuesday->name'
),
array(
'name'=>'wed',
'value'=>'$data->fkidday->wednesday->name'
),
array(
'name'=>'thurs',
'value'=>'$data->fkidday->thursday->name'
),
array(
'name'=>'fri',
'value'=>'$data->fkidday->friday->name'
),
/*'sat',
'sun',
*/
),
));
?>
<script>
$(function() {
// when row is clicked
$('#schedule-grid tbody:first').on('click', 'tr', function() {
// get the ID
var id = $(this).find('td:first').text();
// select the same option in dropdown list with same value
$('#EmpSched_fk_id_sched')
.find("option[value="+ id +"]")
.prop("selected", "selected");
});
});
</script>
Add custom javascript (supposing the create button will submit the form)
$('#form-id').submit(function() {
if $(this).find('#check-box-id').is(':checked') {
// open popup here
}
return false;
});

Forcing print page break after X records using CGridView

I use CGridView to render a result (invoice rows) from a db query. This is done inside a <div> on html page that is later converted to a PDF using wkhtmltopdf and printed. The problem is that today I have no support for page break so if number of invoice rows are greater than 10 the remaining rows are not visible. I can't let the div flow since I have an invoice footer with an absolute position that can't move.
Is there a way to force a page break and continue rendering rows on a separate page?
Below is part of the CGridView code used.
<...plenty of html---->
<div class="invoiceRow">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dpRows,
'cssFile' => Yii::app()->request->baseUrl . '/css/invoice.css',
'summaryText' => '',
'enablePagination' => false,
'columns' => array(
'number',
'name',
'description',
'amount',
array (
'name'=>'value',
'header' => 'netprice',
'value' => 'number_format($data->value,2,","," ")'
),
));
?>
</div>
<---more html ----->
If wkhtml is able to parse css (it seems so) you could try:
<div style="page-break-after:always">
//X invoices here
</div>
if(!empty($model))
{
if($model->content_type==1)
{
$sentences = explode ('<div style="page-break-after: always;"><span style="display:none"> </span></div>',$model->content);
?>
<div id="datashow">
<?php
echo $sentences[0];
?>
</div>
<?php
$dummy=array();
$kcnt=preg_match_all('/page-break-after: always/', $model->content,$dummy);
// echo $model->content;
}
<script>
$("#pagebreakdiv").find(":button").click(function () {
var datashow=$('#datashow');
var a=this.value;
var bid='<?php echo $bid; ?>';
var id='<?php echo $id; ?>';
var pdata = {};
pdata["bitt"] = a;
pdata["bid"] = bid;
pdata["id"] = id;
$.ajax(
{
url : "<?php echo Yii::app()->request->baseUrl; ?>/UserSimple/Contentpagebreak",
type: "POST",
data : pdata,
success:function(data, textStatus, jqXHR)
{
datashow.html(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
});
</script>