Reputation: 415
I have created a form which appears when a button is clicked. This is achieved using Jquery .append
$(document).ready(function(){
$("#adddiet").click(function () {
$('#newbox').append("<div class='span3 diet'><div class='diet-content'><h3>Add a diet</h3></div><div class='content-text2'><form action='sendDietContent.php' method='post'><strong>Title:</strong> <input type='text' name='title'><br><strong>Description:</strong><input type='text' name='description'><br></div><div class='diet-button'><input type='submit'></div></form></div>"); }); });
However when the submit button is clicked nothing happens?
Here is the php that its supposed to call:
<?php
require 'DB/connect.php';
$date = date('Y-m-d H:i:s');
mysqli_query($connect,"INSERT INTO ContentDiet (title, description, dateAdded)
VALUES ('$_POST[title]', '$_POST[description]', '$_POST[$date]')";
?>
Upvotes: 0
Views: 42
Reputation: 6778
Your html code is mal-formed. The form tag starts in a div which is at a lower level than the submit button so the submit button doesn't get included in the form. Try this code:
$(document).ready(function(){
$("#adddiet").click(function () {
$('#newbox').append("<div class='span3 diet'><form action='sendDietContent.php' method='post'><div class='diet-content'><h3>Add a diet</h3></div><div class='content-text2'><strong>Title:</strong> <input type='text' name='title'><br><strong>Description:</strong><input type='text' name='description'><br></div><div class='diet-button'><input type='submit'></div></form></div>"); }); });
Upvotes: 1