This topic is locked

Process Record Values - Edit Page

4/9/2012 1:06:47 PM
PHPRunner General questions
C
copper21 author

Hello all,
Having a bit of trouble and dont know why. I am just trying to auto-populate a field on the edit page, but it is not working. I have dont this type of thing for the add page and worked just fine. I have a field called "file_number" that needs to be filled with the year, bureau_code, and record id. The database I am using is SQL with "file_number" being nvarchar(50). I am getting the date from a php date function, the bureau_code is taken from the bureau_members table where userid is the same as the session of the logged in person, and record id is being pulled from the training_travel_training table using a session variable I setup on the Edit Page:before process event. The record I am editing is also from the training_travel_training table. Any help would be appreciated to tell me as to why this will not put that code into the "file_number" field:
Edit Page: Before Process
$_SESSION['current_record'] = $_GET['editid1'];
Process Record Values
//insert data into file_number field
$rs = CustomQuery("SELECT userid, bureau_code FROM bureau_members WHERE userid=".$_SESSION['UserID']."");

$record = db_fetch_array($rs);
$rs1 = CustomQuery("SELECT traveltrainingid FROM training_travel_training WHERE traveltrainingid=".$_SESSION['current_record']."");

$record1 = db_fetch_array($rs1);
$year = date("Y");
$values["file_number"] = $year . $record["bureau_code"] . $record1["traveltrainingid"];
The field should be filled with something that looks like this: 2012Training123456
2012 being the year, Training being the bureau, and 123546 being the record id.
Thanks,
Brian

C
cgphp 4/10/2012

Try to echo the $_SESSION['current_record'] in the "Before process" event and make sure is not empty:

$_SESSION['current_record'] = $_GET['editid1'];

echo $_SESSION['current_record'];


The second query ($rs1), doesn't make sense: you fetch the field you use in the WEHERE clause.

You may delete it and assign the current_record session value directly to the file_number field value.

$rs = CustomQuery("SELECT bureau_code FROM bureau_members WHERE userid=".$_SESSION['UserID']." LIMIT 1");

$record = db_fetch_array($rs);

$year = date("Y");

$values["file_number"] = $year . $record["bureau_code"] . $_SESSION['current_record'];


Make sure "file_number" is the real name of the field.

C
copper21 author 4/10/2012

Cristian,
Thanks for the reply. I took out the $rs1, you are right it did not make sense. I then echoed "$year . $record["bureau_code"] . $_SESSION['current_record'];" and it showed up on the page correctly, so I know that it works. For some reason, it is not showing up in the "file_number" field. I have the correct field name, I checked and checked again. I then reset the page, nothing. I am using the edit page with tabs if that makes any difference.
Also I get an error with the LIMIT 1 in your statement so I took that out.
Any more suggestions?
Brian

C
cgphp 4/10/2012

Do you get errors in firebug?

C
copper21 author 4/10/2012



Do you get errors in firebug?


I have never used firebug before, so I installed and I think that I am using correctly and I am not getting any errors, just warnings; but not anything pertaining to that field.
The edit page I am trying to do this on is a view. When a user initially fills the form out, on the actual table (not view), the "file_number" field is present on the form, but marked as read only so a value is entered into the database, but it is just empty, not null, if that matters as well.
Thanks,
Brian

C
copper21 author 4/11/2012

Doing a bit of investigating and not sure if this is a bug or not. When I change the property to "Read Only" the code does not work. When I change it to "Text Field" it fills the field in just fine, but the problem is I want the field to be read only. So the solution, at least for now, is to use JS to set the field read only.
So for those of you who are wondering, the code works, but there is something weird about the field settings. The field is set to SQL nvarchar(50) in the database.
Brian