PDA

View Full Version : Fill Form with data from database



lobosan
5 Oct 2011, 3:06 PM
Hi everyone, i made a big form with ext designer and now i need to fill the data depending on the parameter passed on the url (example: mydomain.com/sisconse/designer.html?idform=1)

So depending of the idform i need to make a query to the database, generate the json and fill the form, the json is ready (app/data/loadform.php 28539) but i don't know how to use it to fill the form :( "FichaSenagua"

I hope someone can help me

Thanks in advance

joseph09
5 Oct 2011, 3:38 PM
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.action.Load




formPanel.load({
url: '/path/to/file.php,
method: 'POST',
params: {
id: id,
foo: 'bar',
action: 'loadForm'
},
waitMsg: 'Loading...',
success: function(form, action) {
}
});

lobosan
6 Oct 2011, 1:41 PM
Hi Joseph, thanks for answering :)

I was trying to make it work but i can't :( because i don't know where exactly put the code, i hope you can help me

Here is the code generated by the ext designer

1. designer.js


Ext.Loader.setConfig({
enabled: true
});


Ext.application({
name: 'sisconse',


stores: [
'MyArrayStore'
],


launch: function() {
Ext.QuickTips.init();


var cmp1 = Ext.create('sisconse.view.FichaSenagua', {
renderTo: Ext.getBody()
});
cmp1.show();
}
});


2. FichaSenagua.js


Ext.define('sisconse.view.FichaSenagua', {
extend: 'sisconse.view.ui.FichaSenagua',


initComponent: function() {
var me = this;
me.callParent(arguments);
}
});


3. FichaSenagua.js (in ui folder)


Ext.define('sisconse.view.ui.FichaSenagua', {
extend: 'Ext.form.Panel',
requires: [
'sisconse.view.Cabecera
],


frame: true,
height: 3227,
id: 'FichaSenagua',
width: 1260,
autoScroll: true,
layout: {
type: 'absolute'
},
bodyPadding: 10,
title: 'INFORMACION DE LOS USOS Y APROVECHAMIENTOS HIDRICOS DEL ECUADOR',


initComponent: function() {
var me = this;
me.items = [
{
xtype: 'cabecera',
x: 0,
y: 0,
height: 194,
itemId: 'Cabecera',
width: 1244,
layout: {
type: 'absolute'
}
}
];
me.callParent(arguments);
}
});


4. Cabecera.js (in this file is the field "CbFormularioNo" that i want to fill with the json data)


Ext.define('sisconse.view.ui.Cabecera', {
extend: 'Ext.form.FieldContainer',


height: 194,
width: 1244,
layout: {
type: 'absolute'
}


initComponent: function() {
var me = this;
me.items = [
{
xtype: 'numberfield',
width: 200,
inputId: 'CbFormularioNo',
name: 'CbFormularioNo',
fieldLabel: 'FORMULARIO No',
labelAlign: 'right',
minValue: 1,
x: 790,
y: 10
}
];
me.callParent(arguments);
}
});


5. loadform.php


<?php
header("Content-Type: text/plain");

$data = array(
array('CbFormularioNo'=>'Hola')
);
$info = array(
'success'=>true,
'data'=> $data
);


echo json_encode($info);