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>';
}
$query = "SELECT * FROM `categories`";
$results = mysql_query($query);
echo '<select name="category" class="category" id="guestbook_category">';
while ($row = mysql_fetch_array($results))
{
$catid = $row['cat_id'];
$catname = $row['category'];
echo '<option value="'.$catid.'">'.$catname.'</option>';
}
echo "</select>";
?>
<p class="label">
<label>Message:</label><textarea cols="50" rows="10" name="guestbook_message" id="guestbook_message"></textarea>
</p>
<p class="label">
<label></label>
<span class="postmsg">
</span>
</p>
<p class="submit">
<button type="submit" class="submit" value="Submit" id="guestbook_submit" name="guestbook_submit">Submit</button>
<button type="submit" class="close">Cancel</button>
</p>
</form>
the add_post.php:
Code: [Select]<?php
require_once('functions.php');
db_connect();
$message = $_POST['guestbook_message'];
$name = $_POST['guestbook_name'];
$datetime = $_POST['datetime'];
$category = $_POST['category'];
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.";
}
$bad_word_list = "<object, </object>, <script, <param, </script>, </param>, <a href, &#106;&#97;&#118, &#0000106&#0000097&#0000118&, &#x6A&#x61&#x76&#x61&#x73, &#x09;, &#x0A;, &#x0D;, alert(, <iframe, <embed, <meta, http://, www., .com, .net, .org, dot com, dot net, dot org";
$bad_words = explode(", ",$bad_word_list);
foreach ($bad_words as $word)
{
if (false !== stripos($message, $word))
{
$msgerror = "<strong>Error:</strong> Your message might contain unauthorized words.";
}
}
if($msgerror)
{
$postmsg = $msgerror;
echo "<span class='posterror'>". $postmsg ."</span>";
}
else
{
add_post($message, $name, $datetime, $category);
$postmsg = "<strong>Success!</strong> Your Muttr has been posted.";
echo "<span class='postsuccess'>". $postmsg ."</span>";
}
?>
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;
$.ajax({
type: "POST",
data: dataString,
url: "add_post.php",
timeout: 2000,
cache: false,
success: function(msg)
{
$("#loading").remove();
$(".postmsg").fadeIn(400);
$(".postmsg").html(msg);
setTimeout("$('.postmsg').fadeOut();",60000);
}
});
return false;
});
Warning message
I've put a website that I was doing live and I'm getting this warning message when I try to add a new user when I'm not logged in. It should redirect me back to the login page but I get this
PHP MySQL and DATE
Hi everyoneI have a databse and in one of the columns I have date values such as 2009-March-27. If i have a php interface and want to use a query to select all the rows that is in say october. how
Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the tables with records more than say 100 or so at on go. Can it be possible... If so kindly let me
How to show next and prev records
Hi all,Sorry if this is simple, i'm very new to php, well, any programming language actually.My code runs a query and comes back with the results. Very rarely there may be more than one result.I have
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.I guess this is because of the loose typing of PHP,
need help in update query
hi i have a dynamic form. i need help in how can i use update query when values from dynamic form get pass to php file.currently when i press submit it displays this and does not update fieldsCode:
Log $_POST
How would i log submits on a form, by everyone? I want to then echo the number of submissions.I've tried this:Code: [Select]<?phpif (isset($_POST['submit'])) {$myFile =
Rss feed question
HiMy blog and my website are different. Am i able to take my rss feed from my blog and place it on the index page of my site using php and how to I do it (do I need soap)?
Need Help with a query
Hello, For some reason I am just not getting the right answer when I do this query and not quite sure why? $runinposition = mysql_query("SELECT * FROM bb_off WHERE user='$user' AND test1='test1'
Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to another and whoever they have subscribed to is echoed back on there profile page. my users table