PDA

View Full Version : Loading response text from a form into another form



ray73864
29 May 2007, 5:32 PM
So i have a search form which goes off and gets the correct information from the server (for some reason i have to submit the form twice for the paramaters to go across, the first time Firebug shows no 'POST' params and a Response of 'Loading').

I would like a piece of this information from the ResponseText to get used as the value for a NumberField in another form.

How would i do this? i haven't found much information in the documentation as to how to do it.

PHP Code:



<?php

$link = mysql_pconnect("localhost","test","testpass") or die("Could not connect.");
mysql_select_db("chaplain") or die("Could not select database.");

$strFirstName = $_REQUEST['FirstName'];
$strLastName = $_REQUEST['LastName'];

if (isset($strFirstName) && isset($strLastName)) {
$sql = "SELECT ID, FirstName, LastName FROM student WHERE FirstName = '$strFirstName' AND LastName = '$strLastName'";
$result = mysql_query($sql);

$arr = array();

while ($obj = mysql_fetch_object($result))
{
$arr[] = $obj;
}

echo '{"success":true,"data":' . json_encode($arr) . '}';
} else {
echo '{"success":false}';
}
?>
JS Code:



/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* [email protected]
*
* http://www.extjs.com/license
*/

Ext.onReady(function(){

Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';

Ext.QuickTips.init();

// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';

var ReasonDS = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({url : 'searchReasons.php?type=formal'}),
reader : new Ext.data.JsonReader({},['ID','Name']),
remoteSort : false
});

var AddFormal = new Ext.form.Form({
labelAlign : 'right',
labelWidth : 175
});

AddFormal.fieldset(
{legend : 'Add Formal Record'},
new Ext.form.NumberField({
fieldLabel : 'Record ID',
allowBlank : true,
name : 'StudentID',
id : 'StudentID',
width : 175
}),
new Ext.form.ComboBox({
store : ReasonDS,
displayField : 'Name',
emptyText : 'Choose a reason...',
fieldLabel : 'Reason',
allowBlank : false,
name : 'Reason',
id : 'Reason',
width : 175
}),
new Ext.form.NumberField({
fieldLabel : 'Term',
allowBlank : false,
name : 'Term',
id : 'Term',
width : 175
}),
new Ext.form.DateField({
fieldLabel : 'Date Seen',
allowBlank : false,
name : 'Date',
id : 'Date',
format : 'Y/m/d',
value : '2007/05/25',
width : 175
}),
new Ext.form.TextField({
fieldLabel : 'Time Seen',
allowBlank : false,
name : 'Time',
id : 'Time',
width : 175
}),
new Ext.form.TextArea({
fieldLabel : 'Comments',
allowBlank : true,
name : 'Comments',
id : 'Comments',
width : 500
})
);

ReasonDS.load({params : {code : "3"}});

AddFormal.addButton({
text : 'Create Formal Record',
handler : function() {
AddFormal.submit({
url : 'addFormal.php',
waitMsg : 'Creating formal record for student...'
});
}
});

AddFormal.render('addFormal');

var SearchFormal = new Ext.form.Form({
labelAlign : 'right',
labelWidth : 175
});

SearchFormal.fieldset(
{legend : 'Find Student Record'},
new Ext.form.TextField({
fieldLabel : 'First Name',
allowBlank : false,
name : 'FirstName',
id : 'FirstName',
width : 175
}),
new Ext.form.TextField ({
fieldLabel : 'Last Name',
allowBlank : false,
name : 'LastName',
id : 'LastName',
width : 175
})
);

SearchFormal.addButton({
text : 'Find Student',
handler : function() {
SearchFormal.submit({
url : 'searchFormal.php',
params : {
'FirstName' : Ext.get('FirstName').dom.value,
'LastName' : Ext.get('LastName').dom.value
},
waitMsg : 'Please wait, searching for student record...',
success : function(f, a) {
StudentID.setValue(a.result.data.ID);
}
});
}
});

SearchFormal.render('searchFormal');

});

Post Data (Second press of the 'Find Student' Submit Button):



FirstName Raymond
FirstName Raymond
LastName Herring
LastName Herring
Response Data (Second press of the 'Find Student' Submit Button):



{"success":true,"data":[{"ID":"1","FirstName":"Raymond","LastName":"Herring"}]}

ray73864
31 May 2007, 4:50 PM
anyone??

andrukit
12 Jun 2007, 3:45 AM
HI,

I have no clue as to your first problem (about submitting the form twice) but as for retrieving the ID value try this:



success : function(f, a) {
StudentID.setValue(a.result.data[0].ID);
}


Goodluck