I appreciate any help!
Ok, so we have a php article submission script for our community but on the form page I can not achieve form validation for the life of me.
I have used pretty much any JavaScript method out there, neither work or give any real result of success. I am not skilled enough with PHP to figuere out a PHP method.
Our form goes as this:
[code=php]elseif ($action == “add”) {
// do_auth(1); Disabled so the public can submit
echo create_menu();
echo “<br>
<form action=’?action=process-add’ method=’post’>
<table cellspacing=’0′ cellpadding=’0′ border=’0′ align=’center’>
<tr><th>Uploader:</th><td><input type=’text’ name=’name’ value='” . $session_username . “‘ size=’30’ maxlength=’100′></td></tr>
<tr><th>Title:</th><td><input type=’text’ name=’title’ value='” . $title . “‘ size=’30’ maxlength=’150′></td></tr>
<tr><th>Public:</th><td><input name=’public’ type=’radio’ value=’yes’ checked>Yes <input name=’public’ type=’radio’ value=’no’ disabled>No</td></tr>
<tr><th valign=’top’>Description:</th><td><textarea rows=’10’ cols=’77’ name=’description’>” . $description . “</textarea></td></tr>
<tr><th valign=’top’>Document:</th><td><input type=’text’ name=’text’>” . $text . “</textarea></td></tr>”;
$cat_sql = “SELECT name FROM sa_category”;
db_login();
$cat = @ mysql_query($cat_sql) or die(“Getting Categories error: ” . mysql_error());
$category_r = mysql_num_rows($cat);
mysql_close();
if ($category_r == “0”) {
echo “ERROR: No categories in database!”;
}
else {
echo “<tr><th>Category:</th><td>
<select name=’category’>
<option value=”>Select Onen
<option value=”>————n”;
while ($db = mysql_fetch_array($cat)) {
$cat_name = stripslashes($db[‘name’]);
echo “<option value='” . urlencode($cat_name) . “‘>” . $cat_name . “n”;
}
echo “</select>”;
}
echo ”
</td></tr>
<tr><th>Convert Newlines(\n)<br>to HTML Breaks?</th><td><input type=’radio’ name=’nlbr’ value=’yes’ checked>Yes <input type=’radio’ name=’nlbr’ value=’no’>No</td></tr>
<tr><td><input type=’submit’ value=’Add’></td><td><input type=’reset’></td></tr>
</table>
</form>”;
Then when a user clicks “Add” it gives a javascript window saying “Article successfully posted. Thanks!” found on this line right after the above code:
[code=php]}
elseif ($action == “process-add”) {
$nlbr = $_POST[‘nlbr’];
$name = mysql_escape_string($_POST[‘name’]);
$title = mysql_escape_string($_POST[‘title’]);
$public = mysql_escape_string($_POST[‘public’]);
$date = mysql_escape_string(date(“l F dS, Y h:i A”));
$count = 0;
$description = $_POST[‘description’];
$text = $_POST[‘text’];
$category = urldecode($_POST[‘category’]);
$category = addslashes(mysql_escape_string($category));
if ($nlbr == “yes”) {
$text = nl2br($text);
//if it didnt work as expected, use str_replace() instead
$description = nl2br($description);
//if it didnt work as expected, so use str_replace() instead
//$text = str_replace(“n”, “<br>”, $text); //if the nl2br dont work comment it and uncomment these
//$description = str_replace(“n”, “<br>”, $description); //if the nl2br dont work comment it and uncomment these
}
$text = mysql_escape_string($text);
$description = mysql_escape_string($description);
$sql = “INSERT INTO `sa_page` (`id`, `name`, `title`, `time`, `public`, `count`, `description`, `text`, `category`) VALUES (”, ‘$name’, ‘$title’, ‘$date’, ‘$public’, ‘$count’, ‘$description’, ‘$text’, ‘$category’)”;
db_login();
@ mysql_query($sql) or die(“Error inserting! Reason: ” . mysql_error());
mysql_close();
jsalert(“Article successfully posted. Thanks!”); // Success Javascript Alert //
jsredirect(“?action=view”);
}
My question is, how do I add a form validation into this to ensure that all fields are filled? I have added every possiblity into the form element (onclick, name, etc etc) linking to both embeded and external JavaScript’s with no luck.
Is this [B]jsalert
Thank you. This forum looks amazing.. so much information, I’ll be reading a lot for sure.