php - Redirect to index.html page from server with message -
i want traverse :
index.html(with form data) --> save_message.php(process form data) --> index.html(show success/error message)
my html code :
<script type="text/javascript"> var messageform = $('#message-form'); messageform.submit(function(event){ event.preventdefault(); var form_status = $('<div class="form_status"></div>'); $.ajax({ url: "save_message.php", type: "post", data: $("#message-form").serialize(), datatype: "json", beforesend: function(){ messageform.prepend(form_status.html('<p><i class="fa fa-spinner fa-spin"></i> email sending...</p>').fadein()); }, success: function(data) { if(data.type == 'success'){ alert("thank subscribing!"); form_status.html('<p class="success-message">' + data.message + '</p>').delay(3000); $('#message-form')[0].reset(); }else if(data.type == 'error'){ alert("error on query!"); } } }); }); </script> <form id="message-form" name="message-form" action="save_message.php" method="post"> <div class="form-group"> <label>name *</label> <input type="text" name="full_name" id="full_name" class="form-control" required="required"> </div> <div class="form-group"> <label>email *</label> <input type="email" name="email" id="email" class="form-control" required="required"> </div> <div class="form-group"> <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">submit message</button> </div> </form>
and code in save_message.php file :
<?php header('content-type: application/json'); $status = array( 'type'=>'success', 'message'=>'thank contact us. possible contact ' ); if($_server['request_method'] == "post"){ $full_name = @trim(htmlspecialchars($_post['full_name'])); $email = @trim(htmlspecialchars($_post['email'])); } include 'conn.php'; $sqlquery = "insert suggestion(full_name,email) values('$full_name','$email')"; echo $sqlquery; $result = @mysql_query($sqlquery); if(!$result){ $status = array( 'type'=>'success', 'message'=>'thank contact us. possible contact ' ); } echo json_encode($status); ?>
but not redirecting index.html page. ratheer showing bellow line in save_message.php page.
insert suggestion(full_name,email,phone,title,message,status) values('aaaa','parvej35@gmail.com','12345','aaaaaaaaaaa','sssssssss','new'){"type":"success","message":"thank contact us. possible contact "}
please me.
Comments
Post a Comment