This topic is locked

Error handling & custom messages - how to ?

9/5/2006 4:58:35 AM
PHPRunner General questions
M
marduk author

Greetings,
I am new in PHPRunner and find it great.
However, I cannot find how to handle user errors and display custom messages.
For example, I have a unique index for two column in a table.

When the user violates this rule they get the following

PHP error happened

Technical information

Error type 256

Error description Duplicate entry '1-1' for key 1

URL localhost/admin/omades_tournoua_add.php?

Error file C:\Apache2\htdocs\admin\include\dbconnection.php

Error line 27

SQL query insert into `omades_tournoua` (`tournoua_id`, `omada_id`) values (1, 1)


which I want to replace with a more "user-friendly" message.
Thank you in advance

A
andrewrnd 9/5/2006

Hi
You need to edit generated ..._functions.php which located in Include folder
open it in the text editor, go to error_handler function and copy and paste the following code snippet:

if (!strncmp($errstr,"Duplicate entry",strlen("Duplicate entry")))

{

echo "User friendly message";

exit();

}


just before the following code:

global $strSQL;

if($errno==8 && !strncmp($errstr,"Undefined index",15))

return 0;
M
marduk author 9/5/2006

Thank you for the reply.
But this will be overwritten on the next "build", won't it?
How can I make these changes permanent?

A
andrewrnd 9/5/2006

There are two ways to make these changes permanent:
The first one is to use Template Editor on the Miscellaneous tab, create your own template and change the functions.php file which located in the Include folder
The second one is to edit functions.php file in the Source folder (..\PHPRunner\source\include\functions.php)

T
thesofa 9/6/2006

Greetings,

I am new in PHPRunner and find it great.
However, I cannot find how to handle user errors and display custom messages.
For example, I have a unique index for two column in a table.

When the user violates this rule they get the following

PHP error happened

Technical information

Error type 256

Error description Duplicate entry '1-1' for key 1

URL localhost/admin/omades_tournoua_add.php?

Error file C:\Apache2\htdocs\admin\include\dbconnection.php

Error line 27

SQL query insert into `omades_tournoua` (`tournoua_id`, `omada_id`) values (1, 1)


which I want to replace with a more "user-friendly" message.
Thank you in advance



Hi

I have a table with a compound primary key of 3 fields, I have used the event on the add page, the event is before record add

and I have used the sample code to check for a compound primary key, here is the code.

Probably mangled by the board.

function BeforeAdd(&$values)

{
//********** Check if specific record exists ************

//global $conn;

$detv = $values["detainee"];

$dfdv = $values["DayForDetention"];

$sesv = $values["sess"];

$strSQLExists = "select * from `detentions` where ((detainee=".$detv.") and (DayForDetention=".$dfdv.") and (sess=".$sesv."))";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

echo "<h2><font color=red>Detention for this pupil on this day and for this session has already been booked.<BR>Please enter details for a different detention.</font></h2>";

return false;

}

else

{

// if dont exist do something else

return true;
}

}


If I put in a duplicate record, I get a red message acroos the screen and a blank Add Record screen to try again.

What i would like to do is get the values I have just entered for all the fields as the values in the page and just change the date.

Dunno how to do this.

But this code sticks when you build, so at least you do not have to alter a page each time you build.

D
drh 9/14/2006

Hey sofa,

Thanks, that works beautifully.
It would be nice if the contents would remain in the form and the cursor placed in the first field that needs to be changed.
Fortunately, my app has only 11 fields. It would be very inefficient if my app had many fields and it wiped everything out because of a single character typo.
I am also very interested in keeping the data in the form. Anybody got a solution???
Thanks

Dave

J
Jane 9/15/2006

Dave,
you can save your entered values to use postvalue("editid") as default value on the Edit format dialog on the Formatting tab.
Use postvalue("editid") for the first field, postvalue("editid2") for the second field etc.

D
drh 9/15/2006

Thanks for the response Jane.
So I have tried what you suggested, but I still cannot get the field data to remain on the form when a unique field is duplicated.
Here is what I have done.
First you need to know I followed the directions for displaying the error message just like the sofa suggested. This works just fine.

To keep it simple, lets say

I have 3 fields on the page,

  1. seq which is auto incremented and hidden
  2. SerialNumber which needs to be unique
  3. Model which is from a dropdown list this is also an index (does it make a difference?)
    That is the order in which they are displayed on the form.
    I did what you suggested on the Edit format dialog on the Formatting tab. I set the default to "postvalue('editid')"

    actually I have tried editid, editid1, editid2, editid3.
    All have the same result.....no data is redisplayed in the form if a duplicate SerialNumber is added.
    What am I doing wrong?
    Thanks,

    Dave

kujox 9/15/2006

you can save your entered values to use postvalue("editid") as default value on the Edit format dialog on the Formatting tab.

Use postvalue("editid") for the first field, postvalue("editid2") for the second field etc.


Jane, I can't seem to get this to transfer the values back to the form, the numbers seem to match up with the source of the form?

Sergey Kornilov admin 9/15/2006

In PHPRunner 3.1 use postvalue("value_fieldname") as a Default value. Replace fieldname with the actual field name.

D
drh 9/18/2006

Hello forum,
I am running PHPRunner 3.0. I have tried both solutions in order to repopulate the fields due to a duplicate record when it is to be unique.
I assume since I am still on 3.0 I need to use postvalue("editid") method.
However, the fields still come back blank.
Has anyone successfully got this to work?
Still banging my head against the wall.
Thanks,

Dave

Alexey admin 9/19/2006

Dave,
in PHPRunner 3.0 you need to use the following expressions as Default values:

postvalue("value0")

postvalue("value1")

...

D
drh 9/19/2006

Thanks Alexey,

however, I must be doing something wrong. This is what I entered in the edit format screen default for field model. It is a lookup field which comes from another table.
"postvalue('value2')"
Here is a portion of the source code of the webpage:
<tr><td class=shade>SerialNumber </td><td><input type="text" name="value1" value="">&nbsp;<img src=images/icon_required.gif></td></tr>

<tr><td class=shade>Model </td><td><select size = "1" name="value2" ><option value="">Please select</option><option value="Check Manager 3000">Check Manager 3000</option><option value="Tranz 330">Tranz 330</option><option value="Tranz 380">Tranz 380</option><option value="WA 8300">WA 8300</option><option value="WA 8310">WA 8310</option><option value="Zon Jr Plus">Zon Jr Plus</option></select>&nbsp;<img src=images/icon_required.gif></td></tr>
Now I did follow thesofa's suggestion earlier in this post regarding the error message. That works properly. When I try to add a serial number that already exists, I have a message displayed saying "Serial Number already exists." In the Model field, it says "Please select" instead of the model I had previously chosen.
If I successfully add a unique Serial number, the model is saved correctly. It just will not save the contents of the "Model" field when the Serial number is not unique and redisplay so that the user does not have to enter all the form info in again.
Hope this makes my problem clearer.
Thanks,

Dave

Sergey Kornilov admin 9/21/2006

Dave,
just in case make sure enter default value without double quotes as postvalue('value2').
If this doesn't help send your files to support@xlinesoft.com for investigation.

D
drh 9/22/2006

Thanks Sergey,
I kew I was doing something wrong. This is what I entered in the edit format screen default for field model.
"postvalue('value2')"
I removed the double quotes and all is good and well.
Thank you again.
Dave

Alexey admin 9/25/2006

Dave,
with the latest PHPRunner 3.1 (build 151) the values entered by the user are saved if the error occurs when adding or updating the record.

So you don't need to set Default values now.