I want to know if there's any alternative to my problem.
I have and admin panel where my customer can add/edit/delete buildings. As usual, I have all fields (title, adress, city, etc) in a form with a submit button at the end.
One of the fields is "products affiliates" which is some checkbox you can check to connect the products to the buildings.
I have a "quick add building" (jquery/AJAX) field at the end of the checkbox, if my customer want to quickly add a product at the list. (This is what is problematic cause we can't have 2 embed forms)
I'm on Firefox 29.0.1 fwiw
Here's my form:
<form action="sql.php" method="post" enctype="multipart/form-data">
<table>
[...]
<tr>
<td><label>Produits</label></td>
<td>
<ul class="produits">
<li><label><input name="produits[25]" type="checkbox" value="checked" /> Bière</label></li>
<li><label><input name="produits[2]" type="checkbox" value="checked" /> Fromage</label></li>
<li><label><input name="produits[4]" type="checkbox" value="checked" /> Fruits</label></li>
<li><label><input name="produits[5]" type="checkbox" value="checked" /> Légumes</label></li>
<li><label><input name="produits[1]" type="checkbox" value="checked" /> Viande</label></li>
<li><label><input name="produits[3]" type="checkbox" value="checked" /> Vin</label></li>
</ul>
<form>
<input type="text" name="add_produit" id="add_produit" placeholder="Ajout rapide" />
<button class="btn-mini btn-grey btn-plus" id="add-product"><span></span></button>
<span id="info"></span>
<!-- After I submit this form, I repopulate the above ul with the new content via jquery/ajax -->
</form>
</td>
</tr>
[...]
<tr>
<td colspan="2"><input name="submit" type="submit" value="Ajouter" class="bouton" /></td>
</tr>
</table>
</form>
And here's the jquery/AJAX part:
$(document).ready(function() {
$("#add-product").click(function(e){ // Click on the "quick add" button"
e.preventDefault();
var produit=$("#add_produit").val(); // Get the input value
$.ajax({
type:"post",
url:"../produits/sql.php",
data:"sql=quick_add&type="+produit,
success:function(data){
$("ul.produits").html(data); // Re-populate the ul (I output the new li in the .sql.php)
$("#info").html("Le produit a bien été ajouté!"); // Success message
}
});
});
});
The quick add function is working properly, but as you can suspect, it conflict with the "parent" form. If I hit enter in any parent field, it submit the child (quick add) form...
So, what's my alternative? Or is a fix is possible?
Thx for your help!