This topic is locked

Readonly fields blank out on Edit Page

3/16/2007 8:42:03 AM
PHPRunner General questions
D
dckamo author

Hi,
I have an edit page with 8 fields, 2 of which are Readonly. The values in the Readonly fileds blank out when I display a validation error. The validation takes place in the Before record Updated section.
How can I stop this from happening.
Regards

Kes

Alexey admin 3/16/2007

Kes,
I see what you saying.

Try to do the following.

Open generated edit.php file with a text editor then find and remove these lines from there:

$data["FieldName"]=$evalues["FieldName"];



where FieldNameare your actual readonly field names.

D
dckamo author 3/19/2007

Thank you Alexey for your reply.
Whilst your solution works form a display point of view (ie the fields are visible on the screen) The

$values["FieldName"] in the Beforeedit does not have any values set. So if I have to do any validation using these fields in conjunction with other data entered causes a problem.
Going back to my previous posting. My original intention was to protect a Key field on a edit function.

(the same field would have to be unprotected in the add function). Jane sugguested that I create another field as readonly for my edit function thereby allowing me to have the same field as an input field and a protected field).
First prize for me would have been a facility in the edit function to override the $fdata["EditFormat"]= "Text field" to $fdata["EditFormat"]= "Readonly". I dont know accomplish this.
Thanking You,
Regards

Kes

J
Jane 3/26/2007

You can't use $values["FieldName1"] in the BeforeEdit event if FieldName1 field is readonly on the Edit page.

You need to select value of this field from database. Here is a sample code:

global $conn,$strTableName;

$str = "select FieldName1 from ".$strTableName." where ".$where;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);



Then use $data["FieldName1"] in your validation code.