<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan Coughlin &#124; Web and Graphic Designer &#187; form</title>
	<atom:link href="http://www.ryancoughlin.com/tag/form/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryancoughlin.com</link>
	<description></description>
	<lastBuildDate>Fri, 26 Mar 2010 00:07:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to load data using JSON/PHP using jQuery</title>
		<link>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/</link>
		<comments>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/#comments</comments>
		<pubDate>Wed, 06 May 2009 16:00:53 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=463</guid>
		<description><![CDATA[I have seen a good amount of people wanting to see learn how to load data on their website using jQuery, JSON, and PHP. I thought I would show a simple example that should give you a jump start to your project.
We are going to use $.getJSON() function, you have something like:
$.getJSON("readJSON.php",function(data){
    [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/' rel='bookmark' title='Permanent Link: Time for another iGoogle theme?'>Time for another iGoogle theme?</a> <small>Thinking about making another iGoogle theme and almost done with...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have seen a good amount of people wanting to see learn how to load data on their website using jQuery, JSON, and PHP. I thought I would show a simple example that should give you a jump start to your project.</p>
<p>We are going to use $.getJSON() function, you have something like:</p>
<pre class="js" title="code">$.getJSON("readJSON.php",function(data){
    $.each(data.posts, function(i,post){
          content = '
<div id="post-'+ post.id +'">\n';
	  content += '
<h3>' + post.author + '</h3>

\n';
	  content += '+ post.date_added + '\n';
          content += '' + post.post_content + ';
	  content += ''
<hr />';
	  $("#contents").append(content).fadeIn("slow");
   });
});</div>
</pre>
<p>And example of JSON from the PHP page could look like:</p>
<pre class="js" title="code">{ posts: [{"id":"151","date_added":"2009-05-05 13:40:34","post_content":"This is a test post. jQuery!","author":"Ryan"},
{"id":"152","date_added":"2009-05-05 13:40:55","post_content":"Hey, you got to love Ajax","author":"John"}] }</pre>
<p>That JSON above loads two records that will be displayed on to the page.</p>
<p>The results are being pulled from a MySQL database with tables: <em>id, author, post_content, date_added, and author.</em></p>
<p>I am going to wrap up and article on the jQuery/PHP/JSON comment form with the results loaded on to the page after form submission, stay tuned for a much more in depth explanation of using JSON with PHP and  jQuery.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/05/time-for-another-igoogle-theme/' rel='bookmark' title='Permanent Link: Time for another iGoogle theme?'>Time for another iGoogle theme?</a> <small>Thinking about making another iGoogle theme and almost done with...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to use jQuery to Serialize Ajax Forms</title>
		<link>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/</link>
		<comments>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:17:08 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[serialize]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=455</guid>
		<description><![CDATA[When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.
Instead of declaring all of your data to [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When I first started working with jQuery and submitting forms via Ajax, I&#8217;ve never really used .serialize() and wasn&#8217;t too familiar with it. I started to look in to how it works and what it can do. It can be a huge time saver, especially for larger forms.</p>
<p>Instead of declaring all of your data to be sent using something like:</p>
<pre class="js" title="code">
var fname     = $('#fname').attr('value');
var lname     = $('#lname').attr('value');
$.ajax({
     data: “fname=”+ fname + “&amp; lname=” + lname,
});
</pre>
<p>For a couple of fields above, that is fine, but what if you were creating a form with a large amount of fields. The last thing you would want to do is want to copy/paste that line 20 times for your field. Instead of grabbing each value of each form field we can use jQuery&#8217;s .serialize() to do the dirty work for us, which is a huge time saver. We can use something like:</p>
<pre class="js" title="code">
$(function() {
     $('form').bind('submit',function() { showValues(); return false; });
});
function showValues() {
     var str = $("form").serialize();
     $(".results-box").fadeIn();
     $(".results").text(str);
}
</pre>
<p>The first section binds the submit to a function. When a user submits the form call the function showValues(), the next bit. We grab the form and attach .serialize() to it. We want to serialize all fields within this form and display what data is going to be sent to the sever. A <a href="http://www.ryancoughlin.com/demos/serialize/jquery.serialize.html" target="_blank">working demo</a> has been uploaded.</p>
<p>Now with our data serialized it is ready to be sent over to the server side. Using jQuery .serialize() is much more effiecient compared to retrieving the value using .val().</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/' rel='bookmark' title='Permanent Link: Use jQuery To Submit Form To PHP/MySQL'>Use jQuery To Submit Form To PHP/MySQL</a> <small>Learn to submit a form using jQuery without a page...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Use jQuery To Submit Form To PHP/MySQL</title>
		<link>http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/</link>
		<comments>http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 17:27:15 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=94</guid>
		<description><![CDATA[Learn to submit a form using jQuery without a page refresh and a success callback with the fadeIn() animation. Simple, crisp, and fun.


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Using jQuery to submit a form, is something you are seeing more and more of as jQuery&#8217;s popularity builds. When I first started reading about jQuery and Ajax all I wanted to do was learn how to submit a form using jQuery.</p>
<p>I was so confused and lost, seeing the code was so abstract to me. So in this tutorial, I want to show you how to use the jQuery framework to submit data through a form using jQuery to a PHP page that submits to a database.</p>
<p>We are going to take form data and submit it to a jQuery Ajax call then send that to a PHP page with the data. Check out a <a href="http://www.ryancoughlin.com/demos/ajaxform/index.html" target="_blank">live example</a> of this post.<br />
<span id="more-94"></span></p>
<h3>YOU SHOULD HAVE AN IDEA OF</h3>
<ul>
<li>Some principles of PHP</li>
<li>Basic knowledge of JavaScript and/or <a href="http://www.jquery.com" target="_blank">jQuery framework</a></li>
<li>MySQL</li>
<li>XHTML to build the form</li>
</ul>
<h3>JQUERY FUNCTIONS</h3>
<ul>
<li>submit() &#8211; <a href="http://docs.jquery.com/Events/submit" target="_blank">documentation </a></li>
<li>jQuery.ajax &#8211; <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" target="_blank">documentation </a></li>
</ul>
<h3>XHTML OUTLINE</h3>
<pre title="code" class="xhtml">
<div class="container">
<form id="submit" method="post">
		<fieldset>
			<legend>Enter Information</legend>
			<label for="fname">Client First Name:</label>
<input id="fname" class="text" name="fname" size="20" type="text" />

			<label for="lname">Client Last Name:</label>
<input id="lname" class="text" name="lname" size="20" type="text" />

			<button class="button positive"> <img src="../images/icons/tick.png" alt="" /> Add Client </button>
		</fieldset>
	</form>
<div class="success" style="display:none;">Client has been added.</div>
</div>
</pre>
<h3>JQUERY TO COOK IT ALL</h3>
<pre title="code" class="js">
$(document).ready(function(){
	$("form#submit").submit(function() {
	// we want to store the values from the form input box, then send via ajax below
	var fname     = $('#fname').attr('value');
	var lname     = $('#lname').attr('value');
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "fname="+ fname +"&#038; lname="+ lname,
			success: function(){
				$('form#submit').hide(function(){$('div.success').fadeIn();});

			}
		});
	return false;
	});
});
</pre>
<p><strong>We need to capture the values of the form and we do this by:</strong></p>
<pre title="code" class="js">var fname     = $('#fname').attr('value');</pre>
<p>We are storing it in the variable called &#8220;fname&#8221; and we are taking it from the input field with the id of &#8220;fname&#8221; and the &#8220;.attr(&#8217;value&#8217;) tells jQuery to take the value from the attribute of the value from the input field.</p>
<p>The next section is the bulk of the code.  jQuery makes it very nice and easy to create Ajax calls. As you see, we have type, url, data, and success. These are pretty self explanatory.</p>
<ul>
<li>TYPE &#8211; Are you going to use POST or GET</li>
<li>URL &#8211; What is the URL you are sending the data to</li>
<li>DATA &#8211; The data that you are sending the the URL to be processed</li>
<li>SUCCESS &#8211; What should the function do after the call has been executed</li>
</ul>
<p>Remember that all of these are explained at the jQuery page, you can find the documentation for the Ajax calls <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" target="_blank">here</a>.  There is a slew of options you can run within this one jQuery.ajax() function.</p>
<p>The success part:</p>
<pre title="code" class="js">
success: function(){
     $('form#submit').hide(function(){$('div.success').fadeIn();});
}
</pre>
<p>Once the form is successfully submitted, the form will hide and thanks to jQuery callbacks, we then show the success message.</p>
<h3>THE BACKEND &#8211; AJAX.PHP</h3>
<p>Below is what our ajax.php file will look like, this will carry out the submission. Save this as ajax.php.</p>
<pre title="code" class="php">
&lt;?php

	include ("../../inc/config.inc.php");

	// CLIENT INFORMATION
	$fname        = htmlspecialchars(trim($_POST['fname']));
	$lname        = htmlspecialchars(trim($_POST['lname']));

    $addClient  = "INSERT INTO clients (fname,lname) VALUES ('$fname','$lname')";
    mysql_query($addClient) or die(mysql_error());

?&gt;
</pre>
<p>There you have it, a straight forward guide to to using jQuery, PHP, and a simple HTML form to submit a form. Hopefully this will be a help to users new to the jQuery/Ajax world! If you have any comments or questions get in touch with me, by emailing me or leaving a comment below.</p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/' rel='bookmark' title='Permanent Link: How to use jQuery to Serialize Ajax Forms'>How to use jQuery to Serialize Ajax Forms</a> <small>When I first started working with jQuery and submitting forms...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/06/how-to-load-data-using-jsonphp-using-jquery/' rel='bookmark' title='Permanent Link: How to load data using JSON/PHP using jQuery'>How to load data using JSON/PHP using jQuery</a> <small>I have seen a good amount of people wanting to...</small></li>
<li><a href='http://www.ryancoughlin.com/2008/12/20/jquery-search-and-highlight/' rel='bookmark' title='Permanent Link: jQuery Search And Highlight'>jQuery Search And Highlight</a> <small>Work with the jQuery framework to create a fast Ajax...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/feed/</wfw:commentRss>
		<slash:comments>114</slash:comments>
		</item>
	</channel>
</rss>
