I have searched everywhere, but cannot find a solution for this... I have worked all day trying to get my form to work with jquery. It works to a point.
So, I have my Form open up in a Jquery Modal Window...works fine. A user has his username in the Name field, they need to select a Category, if they don't it returns an error. Lastly, they must fill out a Message, if they do not have a certain # of characters, it returns an error as well. This all works fine. The errors show up appropriately with the Jquery that I have set. The only problem I am having right now is that no matter how many chars I insert into the Message textarea, it returns the "Your message length is too short" error. The string length must be at least 10 characters. Once all is set I want it to show the Success message, then after a couple of seconds close out the jquery window and display the post without having to refresh.
Here is the form code (db_connect(); is a function to connect to the database): Code: [Select]<form class="guestbook_form" action="add_post.php" method="post"> <label>Nickname:</label> <?php db_connect(); if(!$_SESSION['user']['username']) { $username = "Anonymous"; echo '<input type="text" readonly="readonly" name="guestbook_name" class="guestbook_name" value="'.$username.'" />'; } else { $username = $_SESSION['user']['username']; echo '<select name="guestbook_name" class="guestbook_name" id="guestbook_name"> <option value="'. $username .'">'. $username .'</option> <option value="Anonymous">Anonymous</option> </select>'; }
if (strlen($message) < 10) { $msgerror = "<strong>Error:</strong> Your message length is too short."; } if ($category == 1) { $msgerror = "<strong>Error:</strong> Please choose a category."; }
and finally, the jquery/ajax: Code: [Select]$("#guestbook_submit").click(function(){ //get the id //the_id = $(this).attr('id'); $(".postmsg").fadeOut(50);
// show the spinner $('.postmsg').append('<img src="images/loader.gif" alt="Loading" />');
//the main ajax request var name = $("#guestbook_name").val(); var category = $("#guestbook_category").val(); var message = $("#guestbook_message").val();
var dataString = 'name='+ name + '&category=' + category + '&message=' + message;