EasyUI Forum
May 07, 2024, 04:23:56 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: datagrid calls form: how to pass id paramater  (Read 11336 times)
andyj
Jr. Member
**
Posts: 57



View Profile
« on: July 30, 2013, 02:12:13 AM »

I want to call a form to edit a single record from a datagrid containing many records.

The edit form's datasource (data_select.php) dynamically queries a MySQL table to create a json file. It needs to receive the id key parameter.
e.g. data_select.php?entity_id=3 (where 3 is the parameter value being passed)
Code:
<?php
include '../../common/conn.php';
$eid intval($_REQUEST['entity_id']);

$rs mysql_query("SELECT entity_id, FirstName, MiddleName, LastName,Suffix,Phone,Mobile,AltPhone,Fax,Email FROM entity WHERE entity_id = $eid");

$items = array();
while($row mysql_fetch_object($rs)){
array_push($items$row);
}
$result["row"] = $items;

echo str_replace( array( '['']'), ''json_encode($items));
?>

The calling datagrid uses this function to open the edit form:
Code:
function openForm(){
   var row = $('#dg').datagrid('getSelected');
    if (row) {
        url = "../supplieredit/supplieredit.php?entity_id=" + row.entity_id;
        window.open(url,'_parent');
    }
}
This seems to work fine

The edit form itself has its datasource definition  like this:
Code:
$('#fm1').form('load','data_select.php?entity_id='+request.getParameter("entity_id"));
But it is not getting the parameter (herein lies the problem I think).

Can anyone help please? Thanks in advance  Undecided
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 30, 2013, 06:45:32 PM »

Some syntax errors occur in your statement:
Code:
$('#fm1').form('load','data_select.php?entity_id='+request.getParameter("entity_id"));
If the 'entity_id' is generated from your php file, please use the code below.
Code:
$('#fm1').form('load','data_select.php?entity_id='+'<?php echo $eid;?>');
Logged
andyj
Jr. Member
**
Posts: 57



View Profile
« Reply #2 on: July 31, 2013, 01:33:16 AM »

Unfortunately that didn't do the trick.
Code:
$('#fm1').form('load','data_select.php?entity_id='+'<?php echo $eid;?>');
Doesn't get the parameter value of "entity_id" and add it to the url.
View Source shows a blank value, e.g. "supplieredit.php?entity_id="

The order of events is
  • Calling form opens window with &entity_id=[keyfieldvalue] - This works fine
  • Edit form is opened with the url including the parameter and parameter value, e.g. 'supplieredit.php?entity_id=6'
  • BUT the edit form is blank as the parameter is not being captured and passed to the data_select.php file that creates the json datasource
  • If you execute the url 'data_select.php?entity_id=6' in the browser it correctly filters the record where entity_id=6, so no apparent problems there
  • If you execute the url 'data_select.php?entity_id=' or 'data_select.php' in the browser it returns blank, which is what is happening

My only thoughts on why it is not working are:
May be the edit form's "load" method is firing before the url parameter is available to it?
Should I use the form's onBeforeLoad method to get the variable?

Is there any tutorial on how to pass variables via url parameters?
I guess I could use php session variables but it would be nice to be able to manipulate url parameters.
Thanks for your input, greatly appreciated.
Logged
andyj
Jr. Member
**
Posts: 57



View Profile
« Reply #3 on: July 31, 2013, 01:45:42 AM »

Got it now.

It should be:

Code:
$('#fm1').form('load','data_select.php?entity_id='+'<?php echo $_GET['entity_id'];?>');

Thanks for putting me on the right track.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!