Ok , maybe a hard one to explain. I have a form that is built using PHP Form Builder Class
Which looks like:
$form = new form("firstForm");
$form->setAttributes(array(
"width" => 600,
"noAutoFocus" => 1,
"jsIncludesPath" => "lib/php-form-builder-class/includes",
"action" => "uploader.php"
));
$form->addTextbox("Enter a Title:", 'title' , $row['title']);
$form->addTextbox("Enter a Promo Code:", "promo" , $row['promo']);
$form->addWebEditor("Description", "description", $row['description'], array("basic" => 1));
$form->addWebEditor("Terms and Conditions", "terms", $row['terms'], array("basic" => 1));
$form->addHidden("img_urls", $row['img_urls']);
$form->addHidden("destination", $row['destination']);
$form->addHidden("header", $row['headerimg']);
$form->addHidden("cmd", "submit_0");
$form->addButton();
$form->render();
I want to add some jQuery to one of the elements to allow drag and drop, so I've made another form element:
?>
<form id="firstForm" action="uploader.php" method="post" >
<ul class="sortable">
Mags Select:
<?
foreach ($profiles as $mag) {
?>
<div id="sorty"><input type="checkbox" name="units" value="<? echo $mag ?>" /><label><? echo $mag ?></label><br /></div>
<? } ?>
</ul>
</form>
How can I make the jQuery part post through its values 'units' when the PHP Form Builder Class is submitted?
Ive had a look at adding a method to the class, but wondered if there was an easier way?
EDIT:
The PHP Form Builder Class form is self contained, so wherever the jQuery form is in the page, it will always be outside the other.
You could use javascript and transfer the values from the second form INTO (hidden fields in) the first form?
Or similarly you could just build the form and copy the HTML (view source) and use that instead of the raw php, then slot your jQuery drag and drop thing into it that way.
Could you not have your jQuery drag-and-drop form field in the same <form>
tag as all the other fields? That’s the natural way to do it.
Just change your second "firstForm" id to secondForm then do something like this:
$('#firstForm').submit(function(event) {
event.preventDefault();
var postData = $(this).add('#secondForm').serialize();
$.post($(this).attr('action'), postData, function() {
// Complete....
}
});
As your units
input has multiple elements, you can change this to an array like so (take note of change from units
to units[]
):
<div id="sorty"> <!-- I assume this should be ouside the foreach... !-->
<? foreach ($profiles as $mag) { ?>
<input type="checkbox" name="units[]" value="<? echo $mag ?>" />
<label><? echo $mag ?></label><br/>
<? } ?>
</div>
Then you'll receive this just like an array in PHP:
foreach ($_POST['units'] as $key => $value)
{
}