First, you do not need a form to submit using Jquery. So newbies get the old form idea out of your head. Create your textbox or textarea, doesn't matter. The name value doesn't matter either. The important part is the id. We are using wordfish as you can see below
name="whatever" type="text" id="wordfish"
Now create your button, you can just use a div but this example I used a submit button
input type="submit" value="Submit" name="B1" class="wordbutton"
Add your div. This will be used to send the data and to display a message after it is sent
div id="datadiv" Loading... /div
Now for the Javascript Jquery part. Don't forget to remove the spaces before and after script
< script >
$(".wordbutton").click(function() {
word_bird = $("#wordfish").val().replace(/ /g,"+");
Make sure the user entered at least 10 character
but not more the 4000
if ( $("#wordfish").val().length < 10
){
alert("We\'re sorry, you
must enter at least 10 character");
} else if ( $("#wordfish").val().length > 4000 ){
alert("We\'re sorry, there is an 4000 character limit");
}
else {
This sends the form info to the external
save page
$(".datadiv").load("/page_to_store_form_data.php?pid=some_id&text_added="
+ word_bird + "&md=" + new Date().getTime());
// Here is where we clear the feild
$("#wordfish").val("");
}
});
For testing
// page_to_store_form_data.php
$text_added = htmlspecialchars($_REQUEST["text_added"]);
if(empty($text_added)){
echo "Didn't receive anything";
die;
}
else {
echo "$text_added";
}
The php part for a real insert
// page_to_store_form_data.php
$text_added = htmlspecialchars($_REQUEST["text_added"]);
if(empty($text_added)){
echo "Didn't receive anything";
die;
}
$sql ="INSERT INTO SOME_TABLE SET text_feild = '$text_added' ";
$query = mysql_query($sql) or die("Cannot query the database." . mysql_error());
This script is from the
Hostwonderful.com customer project board.