include(); Navigation
Posted: Wed Oct 08, 2008 7:54 am
I'm not really well-versed in PHP since my coding background isn't web based.
I have this new project that has to be platform-independent hence the shift to web application development.
Now the I want the feel of the site to be more like your usual binary app... The problem is with PHP/HTML being mostly stateless.
I am using include(); navigation on my forms and pages primarily for input validation (it's a hassle if you have to return to the previous page every time you make an input error) and my forms have 5 - 10 text input fields which have to be validated.
After doing the first 5 forms I began to feel uncomfortable with the code I was putting out:
Here's a snippet of the main page that handles all the actions on the buttons of the forms:
Now what I get uncomfortable with is the repetitive
It's just one big GoTo *cringe* system now...
The code works fine but it's a bitch to maintain, not to mention the problems that would crop up with CSS... It's gone up to 800 lines now and I'm not even halfway through the forms yet.
I've decided not to use javascript for anything more than layout solutions.
Your thoughts and comments would be greatly appreciated.
I have this new project that has to be platform-independent hence the shift to web application development.
Now the I want the feel of the site to be more like your usual binary app... The problem is with PHP/HTML being mostly stateless.
I am using include(); navigation on my forms and pages primarily for input validation (it's a hassle if you have to return to the previous page every time you make an input error) and my forms have 5 - 10 text input fields which have to be validated.
After doing the first 5 forms I began to feel uncomfortable with the code I was putting out:
Here's a snippet of the main page that handles all the actions on the buttons of the forms:
Code: Select all
switch (true) {
/*Users*/
case isset($_POST['cmdAddNewUser']):
$_SESSION['success'] = false;
include("adduser.php");
break;
case ($_POST['cmdValidateUserAdd']):
include("adduser.php");
break;
case isset($_POST['cmdAddUserSave']):
$qrySaveNewUser = sprintf("INSERT INTO tblUsers VALUES ".
"(NULL, '%s', AES_ENCRYPT('%s', MD5('%s')), ".
"'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');",
mysql_real_escape_string($_SESSION['user_name']),
mysql_real_escape_string($_SESSION['user_pass']),
mysql_real_escape_string($_SESSION['key']),
mysql_real_escape_string($_SESSION['access_level']),
mysql_real_escape_string($_SESSION['salutation']),
mysql_real_escape_string($_SESSION['first']),
mysql_real_escape_string($_SESSION['mi']),
mysql_real_escape_string($_SESSION['last']),
mysql_real_escape_string($_SESSION['birthdate']),
mysql_real_escape_string($_SESSION['street']),
mysql_real_escape_string($_POST['city_id']));
if (!$_SESSION['success']) {
if (mysql_query($qrySaveNewUser)) {
$_SESSION['success'] = false;
}
}
include("showusers.php");
break;
case isset($_POST['cmdAddUserCancel']):
include("showusers.php");
break;
case isset($_POST['cmdEditUser']):
switch (true) {
case isset($_POST['id_no']):
$_SESSION['id_no'] = $_POST['id_no'];
$_SESSION['success'] = false;
include("edituser.php");
break;
default:
include("showusers.php");
break;
}
break;
case isset($_POST['cmdValidateUserEdit']):
include("edituser.php");
break;
Code: Select all
case isset($_POST['foo']):
include("bar.php");
break;
The code works fine but it's a bitch to maintain, not to mention the problems that would crop up with CSS... It's gone up to 800 lines now and I'm not even halfway through the forms yet.
I've decided not to use javascript for anything more than layout solutions.
Your thoughts and comments would be greatly appreciated.