|
|
<form action="ajax/contact.php" method="post" class="ajax"> <div><input type="text" name="navn" placeholder="dit navn"></div> <div><input type="text" name="email" placeholder="din email"></div> <div><textarea name="meddelelse" placeholder="din meddelelse"></textarea></div> <input type="submit" value="Send"> </form> |
$('form.ajax').on('submit, function(){ var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find('[name]').each(function(index, value)) var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function(response) { console.log(response); } }); return false; }); |
<?php if (isset($_POST['name'], $_POST['email'], , $_POST['message'] { Her indsættes kode til INSERT i DB. } |