I am trying to make column row editable using x editable. I'm using codeigniter framework. When I post url to controller using Ajax post, value didn't post into array in controller.
this is my script
this is my view
<td class="numeric"><center><a href="#" class="status_order" name="status" data-type="select"
data-pk="<?=$data['id_faktur'];?>" data-value="<?=$data['status'];?>"
data-title="STATUS PEMBELIAN">
<?=$data['status'];?></a></center></td>
this is my controller
public function edit() {
$data = array (
'status' => $this->input->post('value')
);
$this->admin_order_model->update_status($value, $data);
redirect('admin/produk/penjualan');
}
i don't know why array is empty... help me please
Related
I am making a site for drawing in laravel and I don't know how to make a save button for my drawings,all I need to save for now are the name of the canvas and the size of it,one problem is that the name is stored in an input and I don't know how to access it,the other what do I return after saving it
<a href="{{route('canvas.save',['size' =>$size])}}">
This is how I transfer the size,but the name I don't know yet how to transfer
this is the input where I store it
<input oninput="ChangeInput(this.value)" value="Canvas" type="text" name="title" id="title">
this is how I add the data to the table
public function createDrawing($name,$size,$id){
return Drawing::create([
'name' => $name, //the name of the canvas
'canvas_size' => $size,
'users_id' => $id //this is a foreign key
]);
}
the structure of the route is
Route::get('canvasSave/{size}',[CustomAuthController::class,'SaveDrawing'])->name('canvas.save');
public function SaveDrawing($size){
$check = $this->createDrawing(...,$size,1);
//how do I get the name here from the input
}
What do I return after creating the drawing was stored in the table,my idea was to return a Partial view like a Popup but still don't know how to do it,
I just dont understand how to save it via routes and I'm confused,your help would help a lot
So I managed to do the saving like this in the controller
public function createDrawing(array $data){
return Drawing::create([
'name' => $data['title'],
'canvas_size' => $data['size'],
'users_id' => $data['users_id']
]);
}
public function SaveDrawing(Request $request){
$data = $request->all();
$data['users_id'] = Auth::id();
$check = $this->createDrawing($data);
return View('main.introduction');
}
I did the route into the post like you said and things got clearer after I made the html in form
route:
Route::post('canvasSave',[CustomAuthController::class,'SaveDrawing'])->name('canvas.save');
HTML:
<form action="{{route('canvas.save')}}" method="POST">
#csrf
<input oninput="ChangeInput(this.value)" value="Canvas" type="text" name="title" id="title">
<input type="hidden" name="size" value="{{$size}}">
<button type="submit">Save</button>
</form>
after the save it just returns back to the main page
Use Route::post and pass all the data as a payload (body) on the request. Τhe easiest way is to add them in a form and the size can be a hidden input with the value or use a javascript ajax method to pass them as you like.
I am using cakephp and I want to insert form data in my database, but I am getting the following error:
Table posts for model Post was not found in datasource default.
How can I save my data to database. And in cakephp how can we send data from controller to model?
// this is my view code
echo $this->Form->create('posts', array('action' => 'Add'));
echo $this->Form->input('title', array('label' => 'Enter your email address:'));
echo $this->Form->end('Add');
// this is my controller code
public function Add() {
$this->request->data['posts']['title'] = $this->request->data["posts"]["title"];
$this->Post->save($this->request->data);
}
Error says that model "Post" is not created. You need to create file PostsTable.php and put it in src/Model/Table folder.
Also just try CakePHP tutorial from CakeBook.
I am not able to redirect a custom form to specific action.
What I am trying is
<?= Html::submitButton( 'delete-selected' ,['class' => 'btn btn-primary']) ?>
here delete-selected is my custom action in controller appointment.
I have also tried like this:
public function actionDeleteForm()
{
return $this->render('delete');
return $this->redirect(['delete-selected']);
}
public function actionDeleteSelected()
{
Appointment::deleteAll(['doctor_name' =>4]);
return $this->redirect(['index']);
}
What I am trying to do is actually delete some records using the form. The form name is delete having a select drop-down field.
I want to post the data to action deleteselected and use the $_POST variable in the delete query.
How can I do this?
Thanks.
Any submit button that you put on your form will submit to the url specified in the action parameter of the form. If you haven't specified one, then Yii will use the current controller/action of the form. If you want to override this behavior, then you will need to specify an action for the form. e.g.
$form = ActiveForm::begin([
'action' => 'appointment/delete-selected'
]);
in actionDeleteForm you have
return $this->render('delete');
before
return $this->redirect(['delete-selected'])
this second instruction will never be executed because you have already made a return to the function and then control has already been returned to the caller
This is somewhat a note for Joe Miller's answer. If you are supposed to override the form's action with an action of a controller, make sure you make the value of 'action' as an array:
$form = ActiveForm::begin([
'action' => ['appointment/delete-selected']
]);
It will treat the action as a route to action delete-selected in controller appointment.
I'm trying to pull data from a table, populate a select input with that data, then post that information (and other info) to another table. When the view is rendered, it correctly populates the select with the data required, however when I submit the form, I receive an undefined variable error.
Undefined variable: secondarygenre
View
{{ Form::select('genre', $secondarygenre, null, array('class' => 'form-control', 'id' => 'genre')) }}
Controller
//Data is passed to the form in the view
public function addSubmission() {
$secondarygenre = Genre::lists('friendlyName', 'id');
return View::make('add')
->with('secondarygenre', $secondarygenre);
}
//Form is submitted
public function successfulSubmission() {
$track = new Track();
$track->genre_id = Input::get('genre');
$track->save();
}
If it's populating the select input with data, I know that it's the variable is not undefined.
I apologise if I've missed something, this is my first project with Laravel (or any MVC framework).
Any help would be greatly appreciated!
In the post, you have to also return the view with the variable, it looks like you're only doing that with the get, but you need to use ->with('secondarygenre', $sg) once for each type of request.
been looking for a solution to add a feature for "Custom Columns"... Meaning, I present a list of columns that I can show the user and he selects the ones he wants to see and after the selection the table is updated and add/removes the needed columns.
Didn't find anything on Google (perhaps it has a different name than what I was looking for...)
Anyone has an Idea on how it can be accomplished?
Thanks in advance!
This is not a complete sample, but can give you some clues on how to implement it. You've to define some kind of form to collect the data about how your grid has to be rendered. I recommend you to create a CFormModel class if there are more than 3 input fields. Create a view file with the form and a div or renderPartial of a file containing a grid:
$form = $this->beginWidget('CActiveFormExt');
echo $form->errorSummary($model);
echo $form->labelEx($model,'column1');
echo $form->dropDownList($model
echo $form->error($model,'column1');
echo CHtml::ajaxSubmitButton('UpdateGrid',array('controller/grid'),
array('update'=>'#grid'),
$this->endWidget();
// you can render the 'default options' before any ajax update
$this->renderPartial('_grid',array($customColumns=>array('id','name'),'dataProvider'=>$dataProvider));
In the _grid.php view file:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'grid',
'dataProvider'=>$dataProvider,
'columns' => $customColumns;
));
In the controller:
function actionGrid(){
// recover the form data, and build the custom columns array
$customColumns = array();
$customColumns[] = '.....';
$dataProvider = ...;
$this->renderPartial('_formTrabajo', array('customColumns' => $idSiniestro, 'dataProvider' => $dataProvider'), false);
}
When you click the ajaxSubmitButton, the form is sent to the url specified through ajax, and the reply from the controller must contain the renderPartial of the view containing the grid, so the jQuery call can replace the html correctly. You must pass an array from your controller to the partial view of the grid, with the custom list of columns you want to display.