Update at bottom of post:
I have a page where when a button is pressed, a new window will popup with a form. Below is where I open the popup.
<a><span class="add-on"><i class="icon-plus" style="color: green;" onclick="window.open('<?php echo $this->Html->Url(array('controller' => 'customers', 'action' => 'add?popup')); ?>', 'Add Customer', 'height=630, width=430')"></i></span></a>
When the form is submitted, I need to close that window. The problem I am having now is that the window is closing before the form is fully getting submitted.
Popup Window Code:
<fieldset style="padding-left: 15px;">
<legend>Add Customer</legend>
<?php echo $this->Form->create('Customer', array('inputDefaults' => array('div' => false, 'label' => false))); ?>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<?php echo $this->Form->input('first_name', array('placeholder' => 'First Name')); ?>
</div>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<?php echo $this->Form->input('last_name', array('placeholder' => 'Last Name')); ?>
</div>
</div>
<div class="input-prepend">
<span class="add-on"><i class="icon-globe"></i></span>
<?php echo $this->Form->input('location', array('placeholder' => 'Location')); ?>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-phone"></i></span>
<?php echo $this->Form->input('phone_number', array('class' => 'maskedPhone', 'placeholder' => 'Phone Number')); ?>
</div>
</div>
<div class="control-group">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<?php echo $this->Form->input('email', array('placeholder' => 'Email')); ?>
</div>
</div>
<!-- Close Form -->
<?php echo $this->Form->end(array(
'label' => 'Save Customer',
'id' => 'saveCust',
'class' => 'btn btn-primary',
'div' => false
)); ?>
<?php echo $this->Html->script('jquery.maskedinput.min', array('inline' => false));
echo $this->Html->script('maskedinput', array('inline' => false));
$this->start('script'); ?>
<script type="text/javascript">
$(document).ready(function () {
inputs.maskedInputs();
// Get queryString to close popup window
var queryString = window.location.search.substring(1);
if (queryString == "popup"){
$('#CustomerAddForm').submit(function() {
window.close();
});
}
});
</script>
<?php $this->end(); ?>
Trying to use Ajax call now with no luck:
$('#saveCust').click(function() {
alert("test");
$.ajax({
type: "POST",
url: "<?php echo $this->Html->Url(array('controller' => 'Customers', 'action' => 'add')); ?>",
data: $('#CustomerAddForm').serialize(),
success: function(data)
{
alert("Test");
window.close();
}
})
});
return false;
You have a race condition and the window.close will always win. You need to close when the form is DONE submitting.
Either convert it over to use an Ajax call or call the window.close() in the response of the form submission.
Related
I have a huge question. I am printing out my events in Wordpress (WP) as custom post + acf. Everything works fine but I need to sort my events to show the closest events at the top. Is there any easy way to do this?
My Code looks like this currently:
<?php
/*
Template Name: Program Template
*/
$today = date('Ymd');
$query = new WP_Query(array(
'post_type' => 'program',
'post_status' => 'publish'
));
get_header(); ?>
<div id="particle-canvas">
<h1 class="page-title">Program</h1>
</div>
<div class="container-fluid program">
<div class="row">
<?php while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID(); ?>
<div class="col-md-6 program__program-content">
<div class="overlay-box">
<span><?php $date_value = get_field('date', $post_id);
echo date('d/m/Y', strtotime($date_value)); ?></span>
<img src="<?php the_post_thumbnail_url(array(645, 246)); ?>" alt="">
<div class="details">
<h3><?php echo get_the_title(); ?></h3>
<div class="button">
<a href="<?php echo get_permalink(); ?>">
<p>More</p>
</a>
</div>
</div>
</div>
</div>
<?php } ?>
<?php wp_reset_query(); ?>
</div>
</div>
Please add 'meta_key' in your query, just like this:
$query = new WP_Query(array(
'post_type' => 'program',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'date',
'meta_type' => 'DATE',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Change the 'order' => 'ASC/DESC' according to your requirement.
Hope, this may help you.
I have an ajax uploader in my site that uploads the image but i have to refresh the page in order to view that uploaded image.
How i can avoid this refresh?
My js is
$(function(){
var ul = $('#editprofile-form ul');
$('#drop a').click(function(){
// Simulate a click on the file input button
// to show the file browser dialog
$(this).parent().find('input').click();
});
// Initialize the jQuery File Upload plugin
$('#editprofile-form').fileupload({
// This element will accept file drag/drop uploading
dropZone: $('#drop'),
// This function is called when a file is added to the queue;
// either via the browse button, or via drag/drop:
add: function (e, data) {
var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'+
' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
// Append the file name and file size
tpl.find('p').text(data.files[0].name)
.append('<i>' + formatFileSize(data.files[0].size) + '</i>');
// Add the HTML to the UL element
data.context = tpl.appendTo(ul);
// Initialize the knob plugin
tpl.find('input').knob();
// Listen for clicks on the cancel icon
tpl.find('span').click(function(){
if(tpl.hasClass('working')){
jqXHR.abort();
}
tpl.fadeOut(function(){
tpl.remove();
});
});
// Automatically upload the file once it is added to the queue
var jqXHR = data.submit();
var img = document.getElementById('image-placeholder').innerHTML ;
console.log(img);
},
progress: function(e, data){
// Calculate the completion percentage of the upload
var progress = parseInt(data.loaded / data.total * 100, 10);
// Update the hidden input field and trigger a change
// so that the jQuery knob plugin knows to update the dial
data.context.find('input').val(progress).change();
if(progress == 100){
data.context.removeClass('working');
}
},
fail:function(e, data){
// Something has gone wrong!
data.context.addClass('error');
}
});
// Prevent the default action when a file is dropped on the window
$(document).on('drop dragover', function (e) {
e.preventDefault();
});
// Helper function that formats the file sizes
function formatFileSize(bytes) {
if (typeof bytes !== 'number') {
return '';
}
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
}
});
and my form is
<div class="adminform_wrapp">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'editprofile-form',
'enableAjaxValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'enableClientValidation' => true,
'focus' => array($model, 'first_name'),
'htmlOptions' => array(
'enctype' => 'multipart/form-data'
)
));
//echo $form->errorSummary($model);
?>
<div class="adminform_row">
<?php echo $form->errorSummary($model); ?>
</div>
<div class="adminform_row errorSummary">
<?php echo $response_msg; ?>
</div>
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_First_Name">First Name: <span class="required">*</span></label>
<?php echo $form->textField($model, 'first_name', array('value' => $data['first_name'])); ?>
<?php $form->error($model, 'first_name'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Last_Name">Last Name: <span class="required">*</span></label>
<?php echo $form->textField($model, 'last_name', array('value' => $data['last_name'])); ?>
<?php $form->error($model, 'last_name'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Email">Email: <span class="required">*</span></label>
<?php echo $form->textField($model, 'email', array('value' => $data['email'], 'readonly' => true)); ?>
<?php $form->error($model, 'email'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Phone_No">Phone No: <span class="required">*</span></label>
<?php echo $form->textField($model, 'phone_no', array('value' => $data['phone_no'])); ?>
<?php $form->error($model, 'phone_no'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label>Username:</label>
<span class="profile-username"><?php echo $data['username']; ?></span> </div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label>Edit Profile picture:</label>
<span class="image-placeholder" id="image-placeholder">
<?php
if (file_exists(Yii::getPathOfAlias('webroot') . '/themes/karmora/images/users/' . $data['image']) && $data['image'] != null) {
$u_image_path = $this->theme_baseurl . '/images/users/' . $data['image'];
} else {
$u_image_path = $this->theme_baseurl . '/images/users/default-thumb.png';
}
?>
<img src="<?php echo $u_image_path; ?>" style="width:96px; height:96px;"/>
</span>
<div id='file_browse_wrapper'>
<?php
//echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'upl', array('id' => 'file_browse'));
echo $form->error($model, 'upl');
?>
</div>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<?php echo $form->labelEx($model, 'Address', array('class' => 'fieldname')); ?>
<?php echo $form->textField($model, 'address', array('value' => $data['address'])); ?>
<?php $form->error($model, 'address'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Country">Country: <span class="required">*</span></label>
<select class="error" onchange="print_state('Users_state', this.selectedIndex);" id="Users_country" name ="Users[country]"></select>
<?php $form->error($model, 'country'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_State">State: <span class="required">*</span></label>
<select name ="Users[state]" id ="Users_state"></select>
<script language="javascript">print_state("Users_state", '', "<?php echo $data['state'] ?>");</script>
<?php $form->error($model, 'state'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_City">City: <span class="required">*</span></label>
<?php echo $form->textField($model, 'city', array('value' => $data['city'])); ?>
<?php $form->error($model, 'city'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Zipcode">Zipcode: <span class="required">*</span></label>
<?php echo $form->textField($model, 'zipcode', array('value' => $data['zipcode'])); ?>
<?php $form->error($model, 'zipcode'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<input type="submit" class="adminupdate_btn" value="Update">
<input type="reset" class="admincancel_btn" value="Cancel">
</div>
<!--adminform_row-->
<?php $this->endWidget(); ?>
</div>
Try adding a success event to your fileupload. If you register a success, then just replace the picture with the one already in your jqXHR object. Not sure what plugin you're using but that shouldn't be very hard to accomplish.
I am new to Yii. I need to have a bulk action like bulk delete in CGrid view. I tried by doing in javascript and performing the action using AJAX call. But I dont get what I needed. Please help me solve this.
My view:
<?php $details=$details;
?>
<h3><?php echo $name; ?></h3>
<div id="content" style="margin: 0">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'nimsoft-host-form',
//'enableAjaxValidation'=>true,
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => true, // allow client validation for every field
),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<?php $this->endWidget();?>
<h3><?php echo htmlspecialchars($title); ?></h3>
<h3><?php echo $title; ?></h3>
<div style="padding: 10px;">
<a href="<?php echo $this->createUrl('/Nimsoft/create?id='.$details->host_customer_id);?>" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" >Add New Host to Customer</a>
<a href="<?php echo $this->createUrl('/Nimsoft/Search_all?id='.$details->host_customer_id);?>" title="View All Hosts" class="btn btn-primary circle_ok" style="text-decoration: none;" >View All Hosts</a>
<a href="<?php echo $this->createUrl('/Nimsoft/Search_all',array('id'=>$details->host_customer_id,'isXLSDownload'=>1));?>" title="Export" class="btn btn-primary circle_ok" style="text-decoration: none;" >Export</a>
<a href="<?php echo $this->createUrl('/Nimsoft/Search_all',array('id'=>$details->host_customer_id,'isXLSDownload'=>2));?>" title="Export For All Customers" class="btn btn-primary circle_ok" style="text-decoration: none;" >Export For All Customers</a>
<div style="float:right">
<?php
echo CHtml::link('Upload Customer CSV', array('/Nimsoft/uploadCustomers?id='.$details->host_customer_id), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" } )',
'class'=>'btn btn-primary',
'id'=>'upload_link',
));
?>
</div>
<?php //echo CHtml::Button('Export CSV', array('class' => 'btn btn-primary circle_ok exportCSV-button'));
echo '<form method="post" name="exportCSV-form" id="exportCSV-form" action="' . yii::app()->createUrl('/export/exportCSV') . '">';
echo '<input type="hidden" name="filename" value="HostName">';
$this->renderPartial('_export_list', array(
'model' => $model,
));
echo '</form>';
?>
<div class="innerLR">
<div class="row-fluid">
<?php
Yii::app()->clientScript->registerScript('search_inc', "
$('.exportCSV-button').click(function() {
$.fn.yiiListView.update('exportListView', {
data: $('#search-pm-form').serialize() + '&export=true',
complete: function() {
$('#exportCSV-form').submit();
}
});
});
");?>
<?php
echo CHtml::button("Add Date Entries",array("id"=>"butt"));
?>
<?php
$obj=$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'yiisession-grid',//'host_grid',
'dataProvider'=>$dataProvider,
'type' => 'striped bordered',
'columns'=>array(
array(
'id' => 'selectedIds',
'class' => 'CCheckBoxColumn',
'selectableRows'=>2,
),
array( // display 'create_time' using an expression
'name'=>'host_name',
'value'=>'$data->host_name',
),
array(
'name'=>'host_serviceid',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'status',
'value'=>'$data->status',
),
array(
'class'=>'CButtonColumn',
'template'=>'{edit_date}{update}{delete}',
'htmlOptions'=>array('width'=>'95px'),
'buttons' => array(
'edit_date' => array( //the name {reply} must be same
'label' => 'Add Date', // text label of the button
'url' => 'Yii::app()->createAbsoluteUrl("NimsoftHostsDetails/View", array("id"=>$data->host_id))',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/pencil.png', // image URL of the button. If not set or false, a text link is used, The image must be 16X16 pixels
),
),)
),
))
;
?>
</div>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
</body>
</html>
<div class="separator bottom"></div>
</div>
</div>
<div class="clearfix"></div>
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>
</div>
<script>
hs.preserveContent = false;
hs.dimmingOpacity = 0.75;
hs.zIndexCounter = 10000;
hs.showCredits = false;
// this will disable close when we click on other area than close button
hs.onDimmerClick = function() {
return false;
}
$('.exportCSV-button').click(function() {
$.fn.yiiListView.update('exportListView', {
data: $('#search-faq-form').serialize() + '&export=true',
complete: function() {
$('#exportCSV-form').submit();
}
});
});
</script>
<script type="text/javascript">
var gridId = "yiisession-grid";
$(function(){
$(document).on('click','#yiisession-grid a.bulk-action',function() {
return false;
});
});
function batchActions(values){
var url = $(this).attr('Nimsoft/select_all');
var ids = new Array();
if(values.size()>0){
values.each(function(idx){
ids.push($(this).val());
});
$.ajax({
type: "POST",
url: url,
data: {"ids":ids},
dataType:'json',
success: function(resp){
//alert( "Data Saved: " + resp);
if(resp.status == "success"){
$.fn.yiiGridView.update(gridId);
}else{
alert(resp.msg);
}
}
});
}
}
</script>
<?php
Yii::app()->clientScript->registerScript('edit_date','
$("#butt").click(function(){
var checked=$("#host_grid").yiiGridView("getChecked","host_grid_c1");
var count=checked.length;
if(count>0 && confirm("Do you want to delete these "+count+" item(s)"))
{
$.ajax({
data:{checked:checked},
url:"'.CHtml::normalizeUrl(array('item/remove')).'",
success:function(data){$("#host_grid").yiiGridView("update",{});},
});
}
});
');
?>
My Bulk action code is not working. Please correct me where I went wrong. Thanks in advance.
Answer for yii2:
Checkbox column in a gridview:
GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\CheckboxColumn'],
'id'=>'grid',
'country',
],
]);
Button that fires a javascript and sends a url like this: index.php?r=mycontroller/bulk&action=1&ids=2,6,7,8
this is the button:
<a href="#" onclick="bulkAction('p');">
this is the Javascript:
<script>
function bulkAction(a) {
var keys = $('#grid').yiiGridView('getSelectedRows');
window.location.href='<?php echo Url::to(['mycontroller/bulk']); ?>&action='+a+'&ids='+keys.join();
}
</script>
I have a dropdown in my menu but when I click on the search form field inside the dropdown the dropdown instantly closes.
This is my code:
<button id="sharebutton" type="button" class="btn btn-sm btn-info" data-toggle="dropdown" data-hover="dropdown"
data-close-others="true"><i class="fa fa-search"></i> Search
</button>
<ul class="dropdown-menu extended notification">
<li>
<div class="form-group">
<?php echo $this->Form->create('Search', array('controller' => 'searches', 'action' => 'prodsearch')); ?>
<div class="input-group">
<?php echo $this->Form->input('newsearchterm', array('required' => true, 'class' => 'form-control', 'label' => false, 'placeholder' => 'Search Products...', 'name' => 'newsearchterm')); ?>
<span class="input-group-btn">
<?php
echo $this->Form->button(
'<i class="fa fa-search"></i>',
array(
'type' => 'submit',
'class' => 'btn blue',
),
array('escape' => 'false')
);
?>
</span>
</div>
</div>
<?php echo $this->Form->end(); ?>
</li>
</ul>
(I am using CakePHP which is why the form code is a bit funny)
Add stopPropagation() to the your search form field.
jQuery('.your-form-selector').click(function (e) {
e.stopPropagation();
});
Everything else will work as expected.
JQuery reference
I was just looking for the same thing and found it at here
Remove the "li" tags and try. Like this:
<div class="form-group">
<?php echo $this->Form->create('Search', array('controller' => 'searches', 'action' => 'prodsearch')); ?>
<div class="input-group">
<?php echo $this->Form->input('newsearchterm', array('required' => true, 'class' => 'form-control', 'label' => false, 'placeholder' => 'Search Products...', 'name' => 'newsearchterm')); ?>
<span class="input-group-btn">
<?php
echo $this->Form->button(
'<i class="fa fa-search"></i>',
array(
'type' => 'submit',
'class' => 'btn blue',
),
array('escape' => 'false')
);
?>
</span>
</div>
</div>
<?php echo $this->Form->end(); ?>
</ul>
This worked for me once in adding forms in Bootstrap nav dropdowns.
Im new to yii and ajax. I want to upload an image(profile pic) from a popup window. I used Ajax submit button.
But the file is not getting passed to the controller.
My code in the view is:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'profile-update-form',
'enableAjaxValidation' => true,
'enableClientValidation' => true,
'action' => array('user/profileupdate'),
'htmlOptions'=> array('class' =>'form-horizontal')
));
?>
<?php
$model = User::model()->findByPk(Yii::app()->user->id);
$profile=UserProfile::model()->findByAttributes(array('user_id'=>$model->id));
if(!$profile)
$profile=new UserProfile;
?>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label text10">About me</label>
<div class="col-sm-8">
<?php echo $form->textArea($profile, 'about_me', array('class' => 'form-control form02')); ?>
</div>
<div class="req"> <?php echo $form->error($profile, 'about_me'); ?> </div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label text10">City</label>
<div class="col-sm-8">
<?php echo $form->textField($profile, 'city', array('class' => 'form-control form02', 'id' => 'inputCity')); ?>
</div>
<div class="req"> <?php echo $form->error($profile, 'city'); ?> </div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label text10">Phone</label>
<div class="col-sm-8">
<?php echo $form->textField($profile, 'phone', array('class' => 'form-control form02', 'id' => 'inputPhone')); ?>
</div>
<div class="req"> <?php echo $form->error($profile, 'phone'); ?> </div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label text10">Profile Picture</label>
<div class="col-sm-8">
<?php echo $form->fileField($profile,'profile_picture'); ?>
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'images',
'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
));
?>
</div>
<div class="req"> <?php echo $form->error($profile, 'profile_picture'); ?> </div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label text10"></label>
<div class="col-sm-8">
<span>
<?php
echo CHtml::ajaxSubmitButton('Save', CHtml::normalizeUrl(array('user/profileupdate?rand=' . time())), array(
'dataType'=>'json',
'type'=>'post',
'success'=>'function(data) {
$("#AjaxLoader1").hide();
if(data.status=="success"){
$("#formResult1").html("profile settings changed successfully.");
$("#profile-update-form")[0].reset();
} else {
$.each(data, function(key, val) {
$("#profile-update-form #"+key+"_em_").text(val);
$("#profile-update-form #"+key+"_em_").show();
});
}
}',
'beforeSend'=>'function(){
$("#AjaxLoader1").show();
}'
), array(
'id' => 'profile-update', 'live' => false, 'class' => 'btn btn-s-md btn-info')
);
?>
...
And the code in my Controller is:
public function actionprofileupdate() {
$profile = UserProfile::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
if (!$profile) {
$profile = new UserProfile;
$profile->create_time = time();
$profile->update_time = time();
}
if (isset($_POST['UserProfile'])) {
$profile->attributes = $_POST['UserProfile'];
$profile->about_me = $_POST['UserProfile']['about_me'];
$images = CUploadedFile::getInstance($profile,'profile_picture');
// print_r($_POST);
// print_r($_FILES);
// print_r($images);
// exit();
if (isset($images)) {
if(!is_dir(Yii::getPathOfAlias('webroot').'/images/profilepic/'. 'quy')) {
mkdir(Yii::getPathOfAlias('webroot').'/images/profilepic/'. $profile->profile_picture);
// the default implementation makes it under 777 permission, which you could possibly change recursively before deployment, but here�s less of a headache in case you don�t
}
foreach ($images as $image => $pic) {
echo $pic->name;if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/profilepic/'.$pic->name)) {
$profile->profile_picture = $pic->name;
}
}
$profile->user_id = Yii::app()->user->id;
$profile->update_time = time();
$valid = $profile->validate();
$error = CActiveForm::validate(array($profile));
if ($error == '[]') {
$profile->save(false);
echo CJSON::encode(array('status' => 'success'));
Yii::app()->end();
} else {
$error = CActiveForm::validate(array($profile));
if ($error != '[]')
echo $error;
Yii::app()->end();
exit();
}
}
}
}
Please somebody help me to solve this problem.
When I am using ordinary submit button, the file is tranfering to the controller but when using AjaxSubmitButton the field profilepic is send as blank.
please try it by specifying the enctype in the html options like
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
As of now it is not possible to upload a file or image using AjaxSubmitButton.
From the link below, it has been an open issues that the developer has not solved since 2015.
https://github.com/demogorgorn/yii2-ajax-submit-button/issues