Hi guys,
I have a small, but annoying prob. Hope you can help. I validate data entered into a form, and I'm trying to echo out the form with the offending data parked in the "value" attribute if the validation fails, but they don't show:
The code:
if (isset($_POST['prod_type_button']))
{
$_SESSION['prod_type'] = (isset($_POST['product_type']) AND ctype_alpha($_POST['product_type'])) ? strip_tags($_POST['product_type']) : FALSE;
$_SESSION['cat_assign'] = (isset($_POST['category_assign'])) ? strip_tags(mysql_real_escape_string($_POST['category_assign'])) : FALSE;
$_SESSION['productname'] = (isset($_POST['productname'])) ? strip_tags(mysql_real_escape_string(trim($_POST['productname']))) : FALSE;
$_SESSION['nr_of_options'] = (isset($_POST['nr_of_options']) AND ctype_digit($_POST['nr_of_options']) AND $_POST['nr_of_options'] < 21) ? $_POST['nr_of_options'] : 0;
$_SESSION['graphics'] = (isset($_POST['picornot']) AND ctype_alpha($_POST['picornot'])) ? $_POST['picornot'] : "off";
$_SESSION['clean_desc'] = (isset($_POST['description'])) ? mysql_real_escape_string(strip_tags(trim($_POST['description']))) : FALSE;
//
// We first check if an invalid product type, category and/or name is set:
//
if ($_SESSION['prod_type'] === 'Pick product type' OR $_SESSION['cat_assign'] === 'Pick a category' OR $_SESSION['productname'] == FALSE OR !in_array($_SESSION['cat_assign'], $_SESSION['catarray']))
{
echo "<div class='centertext'><h2 class='hlook1'>PRODUCT AND CATEGORY HANDLING</h2></div><br />
<span class='warning'>Please select a valid product type, product category and/or assign a productname.</span>
<form method='post' action='/formprocessor'>
<fieldset>
<legend>SELECT PRODUCT DETAILS:</legend>
<select name='product_type'>
<option>Pick product type</option>
<option>Physical</option>
<option>Downloadable</option>
</select>
<select name='cat_assign'>
<option>Pick a category</option>\n";
$fetch_category = mysql_query("SELECT cart_id, categoryname FROM categories WHERE cart_id='$cart' ORDER BY categoryname ASC") OR die('Query fetching categories failed');
while($row = mysql_fetch_array($fetch_category))
{
$catremoveslash = stripslashes($row[1]);
echo "<option>$catremoveslash</option>\n";
}
echo "</select>
<p><label>Product Name:</label><input name='productname' value='{$_SESSION['productname']}' type='text' size='20' maxlength='80' /></p><br />
<p><label>Optionrows (0-20):</label><input name='nr_of_options' type='text' size='2' maxlength='2' /><br /></p>
<p><label>Product Picture:</label><input name='picornot' value='on' type='checkbox' /></p><br />
<p><label>Description:</label><textarea rows='8' cols='28' wrap='virtual' value='{$_SESSION['clean_desc']}' name='description'></textarea></p>
<span><input type='submit' name='prod_type_button' value='Process' /></span>
</fieldset>
</form>";
echo '<div class="advice" style="margin-top: 8px"><br /><h2 class="hlook1">CONVENTIONS:</h2><strong>The following criteria must be met:</strong><ol><li>Product MUST be of a type, belong to a category and have a name.</li></ol><hr></hr>';
die("</div><!-- advice end -->");
}
}