PDA

View Full Version : Conditional Save Button on Form Window



zakif
10 May 2012, 10:25 PM
There is a form window after clicking the item on grid panel.

Inside the form window, there is a Save button. I want to hide that button depend on certain condition by doing query to database. I have the codes in .js.php file.

The problem, is, how to get (let's say) id_item value and then put it into a SQL query?

Any advices and solution will be apprectiated.

Thanks in advance.

Here are the codes that failed:


<?
$sql_active = "select id_item, status from tb_item where id_item = ".$ID;
$active = $db->fetchRow($sql_active);
if ($active["status"] <> 1 ) { } else { ?>
buttons:[{
text:'Save',
scope:this,
handler:function(){
this.getForm().getEl().dom.action='item/item/add/';
var me = this;
this.getForm().submit(
{

method:'POST',
waitMsg:'Loading..',
success:function(){
Ext.MessageBox.alert('Status','Successfully saved',function(btn,text){
if(btn =='ok'){
me.windowX.item_grid.load({params:{start:0, limit: <? echo $row_item; ?>}});
me.windowX.close();
}
});
},
failure:function(){
Ext.Msg.alert ('Status','Fail Saved',function(btn,text){
});
}

});

}
}]
<? } ?>

scottmartin
14 May 2012, 7:05 AM
You can make an ajax call to the server and have to server return the value and check the success



$sql = 'SELECT * FROM table WHERE ...' ;
$result = mysql_query($sql); // check result array for values


Regards,
Scott.