How to retain values in yii after submit - php

Doing a search form in PHP YII in which i need to enter 2 dates field Startdate and enddate, after submitting i will be fetching all the records from table where the contacteddate falls between these start and end date.
The problem is after submitting my textbox values are vanishing. How to retain after submitting?

You could use ajax to retrieve the results, instead of the default submit, that way your filter values will not change. The default submit behavior loads(navigates) to a url, hence your values disappear.
You can use CHtml::ajaxSubmitButton() to easily implement this functionality. A sample:
echo CHtml::ajaxSubmitButton(
'AjaxSearch', // label
$url,// url that will search
array('update'=>'#resultdiv'),// the element with id 'resultdiv' will be updated with the search result
$htmlOptions
);

Related

can we use user input data from one form in another form of same page

I have two forms in the same page, the first form will have email, name, password etc.
In a second form there are qualification, skills, institution etc.
I will add data from the first form into one table. I want to take the ID of the data from the first form and add qualifications, skills and institution in another table along with the ID from the first form.
I am doing this in php. Please give me an idea how to implement this.
try to do it with Ajax
User enters email, pass..etc, and clicks submit button after that trigger Ajax Call with form data. Store the data in your table and return Mysql Last Inserted Id. Store Last Inserted Id in your load JS Variable/HTML Hidden value.
Steps :
- User Enters Details and press Submit button
- Ajax call triggers with your data
- get Last Insert id from back-end(ajax response)
- store id in html hidden value or js variable
- use this details for next form

Get Row value from custom gridview when checkbox is checked

I am developing apps in Codeigniter, i am stuck in some code...i just want to know how can i get complete row values if any one check the checkbox and submit, so i should get row value of selected checkbox....
You can use array for while creating rows, use name for your each row's input field as array and when you submit the your form loop over your checkbox array and get the values from other elements using the same key which selected checkbox is having

Populate select box depending on choice of different select box (php / ajax)

Basically I have two forms
The first form Is a simple select box which submits it's value to be processed and inserted into a database (mysql)
However on the same page I have a second form with a select box which will be auto populated with the results from the database(ajax / php), depending on which option was chosen from the first forms select box
So anyway I need some way to store the first select box's chosen value in a variable without submitting the form
You can try.
$('#firstForm').submit(function(){
var firstValue = $('#firstForm select').val()
//do your ajax call.
return false //then return false or
//preventDefault should keep the form from submitting
})

Yii CGridView bulk edit/update?

I want to edit/update, multiple rows together in Yii CGridView.
Say, each row has a checkbox and a single edit/update button, I select multiple rows and by clicking on edit/update button all selected rows are opened for editing and update.
Is this possible with Yii CGridView..??
Use the selectableRows property of the CGridView.
According to Yii Documentation for CGridView
public integer $selectableRows;
the number of table body rows that can be selected. If 0, it means rows cannot be selected. If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected. A selected row will have a CSS class named 'selected'.
You can use the the $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.
Add some more buttons either at the top or bottom of the gridview with actions for edit, delete or whatever action you need to take and pass the key values retrieved above.
If you want to edit rows in-line you can use extension phaActiveColumn which I messed up to support multiple rows (the whole table if desired).
EDIT: well, the extension basically creates an input field replacing the grid cell when user clicks on the cell. The field will have the cell's value for starters and it then sends an ajax call to controller, as soon as the user presses enter, asking to save the value of the field, which will be the user's input.
My addition was to create one such field for every cell in the row and store user input in javascript objects which then get send all at once with one ajax call to the controller. Multiple row updates are supported (creating adequate number of javascript objetcs).
If anyone has any interest in this there it is.
phaEditColumn2
phaAbsActiveColumn2

how to get the dropdown value?

Hi i am using dropdown for display the timezone.The timezone values are come from database.Whenever the user change the value I need to alert the new timezone.For example if user change the time GMT+5.30 to GMT+6.30 then I want to alert GMT+6.30.Here the the dropdown values coming as an array?What can I do to get the values?
If you're using select and you have set values for your options, you can:
$("select#dropdown").change(function(){
alert($(this).val());
});
To do this, you need the jQuery framework. http://www.jquery.com/
checkout http://www.texotela.co.uk/code/jquery/select/ plugin for handling select element, very handy.

Categories