Jump to content

Form Trouble


Xtremer360

Recommended Posts

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);

?>

Link to comment
Share on other sites

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);
}
        
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.