View Full Version : [SOLVED] Attempting to create n checkboxes on a form based on DB query

5 May 2010, 7:13 AM
[UPDATE]: Solved here http://www.extjs.com/forum/showthread.php?100243-SOLVED-element-items-from-php-file-(already-formatted-properly (http://www.extjs.com/forum/showthread.php?100243-SOLVED-element-items-from-php-file-%28already-formatted-properly))

P.S. In retrospect, evant's post looks very similar to what eventually came to be. I guess it just took me a while to come around!

Hi there,

I have an Ext.Form object, and I would like to create a set of checkboxes. The number of checkboxes and the labels on each box should come from a table within a database I'm using.

That said, does anyone have a suggestion for the best approach to this task? I have tried a few approaches that I will detail below.

One includes *attempting* (and failing) to make use of a PHP variable.

I've seen this source before, but the <?php tags don't work in Ext's 'html:' tag. Perhaps I'm not seeing something?

http://stackoverflow.com/questions/1...-from-database (http://stackoverflow.com/questions/1783215/extjs-load-form-items-fields-from-database)

The other approach is the use of an Ext.Grid. I ended up writing code that got a grid to appear on the screen, but no data was present inside it. I'm not sure, however, it if's what I'm looking for. (as stated previously, I just want to make checkboxes on a form with labels which reflect what is in the database).

I was suggested to also investigate simply making an AJAX call and storing the result of a query in an ArrayStore. However I lack the fundamental understanding of how to simply make an AJAX call without the need for user input to do so (hence why I first attempted to use PHP to make the query and store the result in a PHP variable).

So my main question at this point is: based on my task, what is best approach?

Upon getting a response to that (which can be as simple as "The best approach is...", I may or may not have questions relating to a certain approach (if I run into trouble, that is). Also worth noting is that I am working with a machine that does not allow me to work with the latest Firebug, so my debugging has been purely via commenting and trial and error.

Thank you very much for taking the time to read this. Hopefully I can get it figured out!


P.S. This thread is a revision of the thread in the Ext 2.x forums, as I didn't realize I was in the wrong forum! I'm using Ext 3.x! (http://www.extjs.com/forum/showthread.php?98423-Attempting-to-create-n-checkboxes-on-a-form-based-on-DB-query)

5 May 2010, 7:16 AM
Something like this:

var form = new Ext.form.FormPanel(....);
url: 'foo',
success: function(response){
var items = Ext.decode(response.responseText);
var cb = new Ext.form.CheckBoxGroup({
items: items

Where your server returns something like:

[{boxLabel: 'Foo'}, {boxLabel: 'Bar'}]

5 May 2010, 7:56 AM

Sorry if this next question is a little rudimentary. I see that part of the puzzle, but given that the request goes through, how does the request know what to do (i.e. what query to run on what table)? I assume I have to put a php snippet in a file that does the query, correct?

Also, that's an Ajax request, but if I want it to connect to the DB when the page loads (not when a user clicks a button on a form) how do I do this (i.e. how do I instantiate a call using this request function)? That's the biggest hurdle for me, figuring out how to actually make this thing do anything without needing user input. PHP can do that easily, but I don't know how to do this in Ext.Ajax.