Results 1 to 7 of 7

Thread: Form Validation Hopeless

Threaded View

  1. #1
    Join Date
    Jan 2009

    Unhappy Form Validation Hopeless

    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:

    PHP Code:
    elseif ($action == "add") {
    // do_auth(1);  Disabled so the public can submit
    echo create_menu();
        <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";
    $cat = @ mysql_query($cat_sql) or die("Getting Categories error: " mysql_error());
    $category_r mysql_num_rows($cat);
      if (
    $category_r == "0") {
    "ERROR: No categories in database!";
      else {
        <select name='category'>
        <option value=''>Select One\n
        <option value=''>------------\n"
        while (
    $db mysql_fetch_array($cat)) {
    $cat_name stripslashes($db['name']);
    "<option value='" urlencode($cat_name) . "'>" $cat_name "\n";
         <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>

    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:

    PHP Code:
    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')";
    mysql_query($sql) or die("Error inserting! Reason: " mysql_error());
    jsalert("Article successfully posted. Thanks!"); //  Success Javascript Alert   //

    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 jsalert function that handles the alert spoiling this whole deal? I would really appreciate any help!

    Thank you. This forum looks amazing.. so much information, I'll be reading a lot for sure.
    Last edited by lazzledazzle; 08-07-2009 at 02:24 AM. Reason: Forgot to specify something

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center