everyone. I’m a relatively new developer with limited experience in jQuery AJAX and PHP. I’m working on a WordPress plugin that is very much a learning exercise for me as well.
Basic description: On my plugin’s admin page, I have a bunch of forms that will be displayed as modal windows (using jQuery UI) and when filled out, will submit their fields to a separate PHP file for processing. That file will accept the data and prepare it for insertion into the wpdb table I have set up.
Plugin Admin page (PHP):
<div id="form1" title="My Awesome Form">
<form id="frmNewCom">
<fieldset>
<table>
<tr>
<td><label for="name">Community Name</label>
<td><input type="text" name="newComName" id="newComName" />
</tr>
<tr>
<td><label for="lefthead">Left Column Header</label></td>
<td><input type="text" name="newComLefthead" id="newComLefthead" /></td>
</tr>
<tr>
<td><label for="righthead">Right Column Header</label></td>
<td><input type="text" name="newComRighthead" id="newComRighthead" /></td>
</tr>
</table>
</fieldset>
</form>
</div>
jQuery UI code for form ($pcal
is my no-conflict thing):
$pcal('#form1').dialog({
autoOpen: false,
height: 275,
width: 400,
modal: true,
buttons: {
"Add Living Option": function() {
// Functionality for submit
},
Cancel: function() {
$pcal(this).dialog("close");
}
},
close: function() {
// close function
}
});
Now here’s the problem. I’m not really sure what to do from this point. I’ve read a bunch of stuff about using .post()
and .serialize()
, and I’ve gotten myself very confused at this point.
Do you guys have some insight into the proper javascript/jQuery to PHP handling you could lend? I’ve asked this on the WordPress forum as well, but I’ve always found good advice here, so thought I’d ask. Any and all help is appreciated.
A very simple example would be :
This posts the form (
id
=frmNewCom
) in a serialized format (newComName=1&newComLefthead=2&newComName=3
where 1,2 and 3 are the values entered in your form) using .post() and .serialize()then in
test.php
you would access your values like this :The above is a) untested and b) does not contain any prevention against SQL injection should you want to store this in a DB