PDA

View Full Version : AJAX TABS and php form processing



Dragons
02-24-2008, 03:04 AM
1) Script Title: AJAXTABS

3) Describe problem: I have built a main page using the AJAXTABS to code the page navigation.
-When calling a php form into the div content from the menu, user adds data then clicks submit( I have error checking which reloads the same form page first then if there are no errors forwards to the form processingthen onto the result page), my problem is how do i call the and error checking and processing without losing the posted data, I have tried using onclick for the javascript reference to the ajaxtabs script, both in the action part of the form and the submit section off the form and both yeild the same result, also trying to call the form processing, but this only reloads the page as if it was a new instance of it. Is this actually possible with the ajax tabs script? as I need to load the page from header location calls aswell in php

MAIN PAGE WITH AJAXTABS MENU



<?php session_start();
include('mysql_connect.php');
require('required/definitions.php');
if (($_SESSION["level"] != 'admin') && ($_SESSION["level"] != 'manager') && ($_SESSION["level"] != 'staff') && ($_SESSION["level"] != 'retail')) {
header("Location: login_error.php");
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="scripts/ajaxtabs.js">
/*************************************************************************************
* Ajax Tabs Content script- Dynamic Drive DHTML code library (www.dynamicdrive.com)*
* This notice MUST stay intact for legal use *
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code *
*************************************************************************************/
</script>
<title><?php echo BIZ_NAME ?></title>
<link href="buildfit.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
</head>
<body id="web">
<?php
$sql = "SELECT * FROM USERS WHERE USERNAME='" . $_SESSION['username'] . "'";
$result = mysql_query($sql);
$result_row = mysql_fetch_array($result);
?>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="2"><table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="219"><img src="<?php echo IMAGES . LOGO ?>" width="219" height="150"></td>
<td id="biz_address_title" bgcolor="#FFFFFF"><p>&nbsp;&nbsp;Welcome, <?php echo $result_row['CONTACT_NAME']; ?><br>&nbsp;&nbsp;You have been granted '<?php echo $_SESSION['level']; ?>' access.</p></td>
</tr>
</table> </td>
</tr>
<tr>
<td colspan="2" align="center"><ul id="maintab" class="menu">
<li><a href="#" rel="#default">HOME</a></li>
<li><a href="form_user_add.php" rel="content">ADD&nbsp;USER</a></li>
<li><a href="form_user_list.php" rel="content">LIST&nbsp;USER</a></li>
<li><a href="invoice_hours.php" target="_blank">INVOICE&nbsp;HOURS</a></li>
<li><a href="invoice_contract.php" target="_blank">INVOICE&nbsp;CONTRACT</a></li>
<li><a href="contact.php" rel="content">ADD&nbsp;CONTRACT</a></li>
<li><a href="contact.php" rel="content">LIST&nbsp;CONTRACTS</a></li>
<li><a href="contact.php" rel="content">ADD&nbsp;SUPPLIER</a></li>
<li><a href="contact.php" rel="content">LIST&nbsp;SUPPLIERS</a></li>
</ul></td>
</tr>
<tr>
<td colspan="2" align="center" id="content"><div class="invoice_title">LOGIN SUCCESSFUL</div></td>
</tr>
<tr>
<td colspan="2" align="center" id="biz_address_title">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td id="biz_address_title" align="right"><a href="user_logout.php">LOGOUT</a></td>
</tr>
</table>
<script type="text/javascript">

var process=new ddajaxtabs("maintab", "content")
process.setpersist(true)
process.init()

</script>
</body>
</html>
<?php mysql_close($link); ?>


CODE BELOW FOR FORM



<?php session_start();
include('mysql_connect.php');
require('required/definitions.php');
if (($_SESSION["level"] != 'admin') && ($_SESSION["level"] != 'manager')) {
header("Location: login_error.php");
}
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if ($_POST['business_name']=='')
$arrErrors['business_name'] = 'Please provide a business name.';
if ($_POST['contact_name']=='')
$arrErrors['contact_name'] = 'Please provide your name.';
if ($_POST['username']=='')
$arrErrors['username'] = 'Please provide a username.';
if ($_POST['password']=='')
$arrErrors['password'] = 'Please provide a password.';
if (count($arrErrors) == 0) {
// Insert form processing here.
$sql = "INSERT INTO USERS (BUSINESS_NAME, ABN, CONTACT_NAME, TELEPHONE, FAX, EMAIL, WEBSITE, STREET_ADDRESS, SUBURB, STATE, COUNTRY, USERNAME, PASSWORD, LEVEL)
VALUES ('" . $_POST['business_name'] . "', '" . $_POST['abn'] . "', '" . $_POST['contact_name'] . "', '" . $_POST['telephone'] .
"', '" . $_POST['fax'] . "', '" . $_POST['email'] . "', '" . $_POST['website'] . "', '" . $_POST['street_address'] . "', '" . $_POST['suburb'] .
"', '" . $_POST['state'] . "', '" . $_POST['country'] . "', '" . $_POST['username'] . "', '" . $_POST['password'] . "', '" . $_POST['level'] . "')";

$result = mysql_query($sql);
header("Location: form_user_list.php");
} else {
$strError = '<div class="formerror"><p><img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
foreach ($arrErrors as $error) {
$strError .= "<li class='indent'>$error</li>";
}
$strError .= '</ul></div>';
}
}
?>
<link href="buildfit.css" rel="stylesheet" type="text/css" />
<div align="center" class="invoice_sub_title">&nbsp;&nbsp;<font color="#000000">ADD NEW USERS</font></div>
<div align="center">&nbsp;&nbsp;* - <font color="#FF0000">Indicated Required Fields</font></div>
<table border="0" cellpadding="0" cellspacing="0" align="center" width="500">
<tr>
<td><?php echo $strError; ?></td>
</tr>
<tr>
<td class="useradd"><br />
<form method="post" action="<?php echo $PHP_SELF; ?>">
<p<?php if (!empty($arrErrors['business_name'])) echo ' class="formerror"'; ?>><label for="business_name">* Business Name:</label><input name="business_name" type="Text" size="35" id="business_name" value="<?php echo $_POST['business_name'] ?>">
<?php if (!empty($arrErrors['business_name'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['business_name'].'</span>'; ?></p>
<p><label for="abn">ABN:</label><input type="Text" size="35" name="abn" value="<?php echo $_POST['abn'] ?>"></p>
<p<?php if (!empty($arrErrors['contact_name'])) echo ' class="formerror"'; ?>>
<label for="contact_name">* Name:</label>
<input name="contact_name" type="Text" size="35" id="contact_name" value="<?php echo $_POST['contact_name'] ?>">
<?php if (!empty($arrErrors['contact_name'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['contact_name'].'</span>'; ?></p>
<p><label for="telephone">Telephone:</label><input type="Text" size="35" name="telephone" value="<?php echo $_POST['telephone'] ?>"></p>
<p><label for="fax">Fax:</label><input type="Text" name="fax" size="35" value="<?php echo $_POST['fax'] ?>"></p>
<p><label for="email">Email:</label><input type="Text" size="35" name="email" value="<?php echo $_POST['email'] ?>"></p>
<p><label for="website">Website:</label><input type="Text" size="35" name="website" value="<?php echo $_POST['website'] ?>"></p>
<p><label for="street_address">Street Address:</label><input type="Text" size="35" name="street_address"></p>
<p><label for="suburb">Suburb:</label><input type="Text" size="35" name="suburb" value="<?php echo $_POST['suburb'] ?>"></p>
<p><label for="state">State:</label><input type="Text" size="35" name="state" value="<?php echo $_POST['state'] ?>"></p>
<p><label for="country">Country:</label><input type="Text" size="35" name="country" value="Australia"></p>
<p<?php if (!empty($arrErrors['username'])) echo ' class="formerror"'; ?>>
<label for="username">* Username:</label>
<input name="username" type="Text" size="35" id="username" value="<?php echo $_POST['username'] ?>">
<?php if (!empty($arrErrors['username'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['username'].'</span>'; ?></p>
<p<?php if (!empty($arrErrors['password'])) echo ' class="formerror"'; ?>>
<label for="password">* Password:</label>
<input name="password" type="Text" size="35" id="password" value="<?php echo $_POST['password'] ?>">
<?php if (!empty($arrErrors['password'])) echo '<img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['password'].'</span>'; ?></p>
<p><label for="level">* Level:</label><select name="level">
<option value="client">Client</option>
<option value="client">Supplier</option>
<option value="staff">Staff</option>
<option value="manager">Manager</option>
<option value="admin">Admin</option>
</select></p>
<p align="center"><input type="submit" name="Submit" value="Submit"></p>
</form></td>
</tr>
</table>
<?php mysql_close($link); ?>

ddadmin
02-25-2008, 10:54 PM
Have you tried using the IFRAME option of the script to display the form page? In other words, rel="IFRAME"