rlelek Posted November 15, 2008 Share Posted November 15, 2008 Hello all! I was just curious how one would go about making a custom error array for *application* error reporting. In other words, I don't want this to replace PHP error handling, but rather inform me and the user of the script about any errors that occurred. I assume this is fairly easy and I am probably over thinking this. Here's what I came up with... <?php if ($result == "error"){ $error[] = "There was an Error"; } if ($error){ foreach($error as $error){ echo $error; } } ?> Is this the general concept? Anything you would add/remove? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132779-solved-custom-error-array-not-to-replace-php-error-handling/ Share on other sites More sharing options...
Caesar Posted November 15, 2008 Share Posted November 15, 2008 One approach... <?php if(!$f->login($sess)) $alert->errors('login'); ?> ...You can then have a nice error handling method you can pass a simple value to and it will return the correct error accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/132779-solved-custom-error-array-not-to-replace-php-error-handling/#findComment-690537 Share on other sites More sharing options...
rlelek Posted November 15, 2008 Author Share Posted November 15, 2008 since this is OO-PHP... if(!$f->login($sess)) $alert->errors('login'); Do I need to define these classes or are they predefined in PHP? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132779-solved-custom-error-array-not-to-replace-php-error-handling/#findComment-690557 Share on other sites More sharing options...
Lodius2000 Posted November 15, 2008 Share Posted November 15, 2008 rlelek I posted this the other day in another thread chronister, look into that book i talked about earlier 'learning php 5' his method is really nice, makes functions for form processing... simple validation lines and all sorts of goodies. heres the main page logic for all my form pages, just put this at the top and then build all the functions <?php if($_POST['_submit_check']){ //$_POST['_submit_check'] is a hidden field, makes redisplay possible if($form_errors = validate_form()){ show_form($form_errors); } else { process_form(); } } else { show_form(); } function show_form($errors = '') { // make the form here //start with if ($errors){ print 'Please correct these errors: <ul><li>'; print implode('</li><li>', $errors); print '</li></ul>'; } } function validate_form(){ //contains simple validation like //check that username is entered if (trim(strlen($username)) == 0) { $errors[]= "You must enter a username."; } } function process_form(){ //what do you want to do with the entered data, whatever it is, do it here } ?> that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/132779-solved-custom-error-array-not-to-replace-php-error-handling/#findComment-690592 Share on other sites More sharing options...
rlelek Posted November 15, 2008 Author Share Posted November 15, 2008 Thanks Lodius2000! This is exactly what I was looking for, but as with all scripts, it will need some modification. Thread solved Quote Link to comment https://forums.phpfreaks.com/topic/132779-solved-custom-error-array-not-to-replace-php-error-handling/#findComment-690870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.