PDA

View Full Version : Help POST parameter from Ext.form to PHP



Gusti
19 May 2011, 8:40 AM
Hi all.. I'm new to ExtJS, and currently i'm using Ext JS 3.0.
I'm using Ext.chart.LineChart to show graph data from date range.
This is my graph :
26145


I have problem when i tried to post parameters from view to my controller (php code). Here's the problem :



items:
new Ext.TabPanel({
activeTab:0,
defaults:{autoScroll: true},

items: [{
title : 'Graph Node 1',
items : [
new Ext.form.FormPanel({
id: 'date_range',
//name : 'date',
labelWidth: 100, // label settings here cascade unless overridden
frame:true,
bodyStyle:'padding:5px 5px 0',
//width: 350,
defaults: {width: 300},
defaultType: 'textfield',
items: [
new Ext.form.DateField({
fieldLabel: 'From',
width: 50,
id: 'date_range_from',
name: 'date_range_from',
value: new Date(),
format: 'd M Y',
readOnly: false,
maxValue: '<?php echo date("d M Y"); ?>'
}),
new Ext.form.TimeField({
fieldLabel: 'Pick time',
id: 'time_from',
name: 'time_from',
minValue : '09:00:00',
maxValue : '18:00:00',
increment : 1,
format : 'H:i:s'
}),
new Ext.form.DateField({
fieldLabel: 'To',
width: 50,
id: 'date_range_to',
name: 'date_rang_to',
value: new Date(),
format: 'd M Y',
readOnly: false,
name: 'date_range_to',
maxValue: '<?php echo date("d M Y"); ?>'
}),
new Ext.form.TimeField({
fieldLabel: 'Pick time',
id: 'time_to',
name: 'time_to',
minValue : '09:00:00',
maxValue : '18:00:00',
increment : 1,
format : 'H:i:s'
})

],
buttons: [{
text: 'Render',
type : 'submit',
url: 'desktop_charts.php',
method : 'POST',
handler: function() {
formPanel = Ext.getCmp('date_range');
formPanel.getForm().submit({
params: {date_range_from: 'date_range_from',
date_range_to :'date_range_to',
time_from : 'time_from',
time_to : 'time_to'}
});
}
}]
}),
new Ext.Panel({
iconCls:'chart',
title: 'X : Date and Time Received - Y : Temperature',
frame:true,
layout:'fit',
//autoScroll : true,
url: '../ext-3.0/resources/charts.swf',
items : new Ext.chart.LineChart({
//url: '../ext-3.0/resources/charts.swf',
autoLoad: false,
//autoLoad: {url: 'desktop_charts.php', scope: this},
store: date_store,
dataField: 'date_received',
xField: 'date_received',
yField: 'temperature',

yAxis: new Ext.chart.NumericAxis({
displayName: 'Temperature',
labelRenderer : Ext.util.Format.numberRenderer('00.00'),
majorUnit : 0.5
}),

tipRenderer : function(chart, record){
return Ext.util.Format.number(record.data.temperature, '00.00') + ' temperature in ' + record.data.date_received;
}

})
})
]
}


It is true when i tried to access my desktop_charts.php like this?

formPanel = Ext.getCmp('date_range');
formPanel.getForm().submit({ })

Because nothing was appear :((( and when i open my firebug this is the one that appear :

uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost/TA/desktop_sms/ext-3.0/adapter/ext/ext-base.js :: i :: line 8" data: no]

Can anyone HELP me out of this????? :( please i'm so stuckk
Thanks for your kindda atention sorry if my english was bad

friend
19 May 2011, 8:53 AM
Check the Ext.form.BasicForm (http://dev.sencha.com/deploy/ext-3.3.1/docs/?class=Ext.form.BasicForm) API docs and look at the submit() method. You'll see that you're leaving out a whole bunch of required config:




myFormPanel.getForm().submit({
clientValidation: true,
url: 'updateConsignment.php',
params: {
newStatus: 'delivered'
},
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
}
}
});

Gusti
19 May 2011, 9:18 AM
OOh got that. Thank you very muchh :D the errors now was dissapear.
But why i cannot render the data i've posted into Linechart? The linechart doesn't show anything :( its there something wrong with my Ext.chart.LineChart? Why it cannot rendered?
Thanks for your kindness :) very much



new Ext.Panel({
iconCls:'chart',
title: 'X : Date and Time Received - Y : Temperature',
frame:true,
layout:'fit',
//autoScroll : true,
url: '../ext-3.0/resources/charts.swf',
items : new Ext.chart.LineChart({
//url: '../ext-3.0/resources/charts.swf',
autoLoad: false,
dataField: 'date_received',
xField: 'date_received',
yField: 'temperature',

yAxis: new Ext.chart.NumericAxis({
displayName: 'Temperature',
labelRenderer : Ext.util.Format.numberRenderer('00.00'),
majorUnit : 0.5
}),

tipRenderer : function(chart, record){
return Ext.util.Format.number(record.data.temperature, '00.00') + ' temperature in ' + record.data.date_received;
}

})
})
]
}



BTW, this is my php code :


<?php
header("Cache-Control: no-cache");
sleep(2);

global $con;
$con = mysql_connect("localhost","root","wireless");
mysql_select_db("wsn", $con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

if(isset($_POST['submit'])) {
$dateFrom = $_POST['date_range_from'];
$dateTo = $_POST['date_range_to'];
$timeFrom = $_POST['time_from'];
$timeTo = $_POST['time_to'];
}

$query = "SELECT date_received, temperature, node_id FROM `sensor_results` WHERE node_id = '1' AND date_received BETWEEN " .$dateFrom." ". $time_from. "AND". $dateTo." ".$time_to ;
$result = mysql_query($query);
$dataset1 = array();
while($row = mysql_fetch_array($result))
{
$dataset1['date_received'] = $row [date_received];
$dataset1['temperature'] = $row [temperature];
$data[] = $dataset1;
}
//$response = array( 'data' => $dataset1 );
echo json_encode($data);


mysql_close($con);

?>



Hope you or anyone will reply my thread again :(