Xtremer360 Posted November 24, 2010 Share Posted November 24, 2010 I'm not sure if this is a php issue or jquery issue. When I complete the form and hit submit it puts the successful message up like its supposed to but also with the fields still filled in the form which it shouldn't be doing and it doesn't actually post in the database so I'm not sure if its a php issue or jquery issue. <script type="text/javascript"> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $("input.submit").click(function() { $('div.message-error').hide(); var templatename = $("input#templatename").val(); if (templatename == "") { $("div.message-error").show(); $("input#templatename").focus(); return false; } var headercode = $("textarea#headercode").val(); if (headercode == "") { $("div.message-error").show(); $("textarea#headercode").focus(); return false; } var footercode = $("textarea#footercode").val(); if (footercode == "") { $("div.message-error").show(); $("textarea#footercode").focus(); return false; } var dataString = 'templatename='+ templatename+ '&headercode=' + headercode + '&footercode=' + footercode; $.ajax({ type: "POST", url: "processes/template.php", data: dataString, success: function() { $("div.message-success").show(); return true; } }); return false; }); }); </script> <!-- Form --> <form action="#" name="templateform" > <fieldset> <legend>Add New Template</legend> <div class="field required"> <label for="templatename">Template Name</label> <input type="text" class="text" name="templatename" id="templatename" title="Template Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="headercode">Header Code</label> <textarea name="headercode" id="headercode" title="Header Code"></textarea> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="footercode">Footer Code</label> <textarea name="footercode" id="footercode" title="Footer Code"></textarea> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="submit" class="submit" name="submittemplate" id="submittemplate" title="Submit Template" value="Submit Template"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Template was added to the database.</p> </div> <!-- /Messages --> validation page <?php // Include the database page include ('inc/dbconfig.php'); if ((isset($_POST['templatename'])) && (strlen(trim($_POST['templatename'])) > 0)) { $templatename = stripslashes(strip_tags($_POST['templatename'])); } else {$templatename = 'No name entered';} if ((isset($_POST['headercode'])) && (strlen(trim($_POST['headercode'])) > 0)) { $headercode = stripslashes(strip_tags($_POST['headercode'])); } else {$headercode = 'No name entered';} if ((isset($_POST['footercode'])) && (strlen(trim($_POST['footercode'])) > 0)) { $footercode = stripslashes(strip_tags($_POST['footercode'])); } else {$footercode = 'No name entered';} $query = "INSERT INTO `templates` (templatename, header, footer, creator_id, datecreated) VALUES ('".$divisionname."','".$headercode."','".$footercode."' 1, NOW())"; mysql_query($query); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 24, 2010 Share Posted November 24, 2010 echo your $query and see what it displays. Quote Link to comment Share on other sites More sharing options...
harristweed Posted November 24, 2010 Share Posted November 24, 2010 are you sure there is a database connection? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 are you sure there is a database connection? I have the database connection file attached is there a way to see if there is a connection in the validation script? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 echo your $query and see what it displays. I echoed the query and afterwards it didn't end up echoing anything after I submitted my form. So I know there's a problem somewhere. Lol. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 Your form tag seems to be missing a method="post" . . . Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 I was following this tutorial which helped tremendously and saw that you can include that in the ajax function. http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 Then I guess I'd have to say that the problem lies in the AJAX/JS. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 Okay however I just want to clarify something real fast. With the functions of stripslashes, trim, and strip tags become meaningless don't they because you can use mysql_real_escape_string? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 24, 2010 Author Share Posted November 24, 2010 I'm sorry for dragging out this topic but one last thing. Someone told me I should redo it and this is what I came up with instead for the validate form. I'm just curious to see if I have any tags wrong or parenthesis wrong also would like to know in fact this should work in theory. The reason why I don't have mysql_real_escape_string for the header and footer codes is because that will have html coding inside of it and only admins can fill out this form. So I'm not too worried about it right now. But other than that is everything alright? <?php // Include the database page include ('inc/dbconfig.php'); if (isset($_POST['submittemplate'])) { $templatename = mysql_real_escape_string($_POST['templatename']); $headercode = $_POST['headercode']; $footercode = $_POST['footercode']; $query = "INSERT INTO `templates` (templatename, header, footer, creator_id, datecreated) VALUES ('".$templatename."','".$headercode."','".$footercode."', 1, NOW())"; mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted November 25, 2010 Author Share Posted November 25, 2010 FINALLY! I was stupid and in one of the files I didn't have the right location for my dbconfig file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.