jquery - AJAX form submit Codeigniter -
i'm trying submit form using ajax / jquery view code igniter model. if post value has been passed model returns true.
my view showing success message regardless. please point out i'm going wrong?
here function controller:
function bookings(){ $this->load->helper('url'); if($_post): echo $_post["name"]; // database stuff here save comment. // return false if db failed // else return true; endif; }
here relevant javascript & form view:
<div id="booking-form-container" class="fb-dialogue"> <div id="info">entery details below make group booking:</div> <!-- hold response / error message server --> <div id="response"></div> <form id="bookingsform" method="post" action="eventguide/bookings"> <label class="description" for="element_1">full name: </label> <div> <input id="name" name="name" class="element text medium" type="text" maxlength="255" value="<?php echo $me['first_name'] . ' ' . $me['last_name']; ?>"/> </div> <label class="description" for="element_2">email: </label> <div> <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo $me['email']; ?>"/> </div> <label class="description" for="element_3">mobile number: </label> <div> <input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/> </div> <label class="description" for="element_5">choose you're event: </label> <div> <select class="element select medium" id="element_5" name="element_5"> <option value="" selected="selected"></option> <option value="1" >first option</option> <option value="2" >second option</option> <option value="3" >third option</option> </select> </div> <label class="description" for="element_4">group size: </label> <div> <input id="element_2" name="element_4" class="element text medium" type="number" value="10"/> </div> <label class="description" for="element_6">questions or special requirements? </label> <div> <textarea id="element_6" name="element_6" class="element textarea medium"></textarea> </div> </form> </div> <script type="text/javascript"> var mydetails = $("#booking-form-container").dialog({autoopen: false, modal: true, draggable: true, resizable: false, bgiframe: true, width: '400px', zindex: 9999, position: ['50%', 100]}); function showdetailsdialog() { $("#booking-form-container").dialog("option", "title", "group bookings"); $("#booking-form-container").dialog({buttons: { "close": {text: 'close', priority: 'secondary', class: 'btn', click: function() { $(this).dialog("close"); }}, "confirm booking": {text: 'confirm booking', priority: 'primary', class: 'btn btn-primary', click: function() { $('#bookingsform').submit(); }} } }); $("#booking-form-container").dialog("open"); } $("#bookingsform").submit(function(event) { event.preventdefault(); datastring = $("#bookingsform").serialize(); $.ajax({ type: "post", url: "<?php echo base_url(); ?>eventguide/bookings", data: datastring, success: function(data){ alert('successful!'); } }); return false; //stop actual form post !important! }); </script>
what want first check see have data
if(isset($_post) && isset($_post['name'])) { // post in $_post array, stuff echo htmlspecialchars($_post['name'], ent_quotes, 'utf-8'); }
Comments
Post a Comment