Note that there are some explanatory texts on larger screens.

plurals
  1. POForm validated but still submitting without values?
    primarykey
    data
    text
    <p>im using javascript validation to check for values within each form field before the form sends to the database but when i click submit the form still sends even without any values. To test it i clicked on each of the fields to clear them and then tried submittin the button</p> <p><strong>here is the form</strong></p> <pre><code> &lt;form method="post" action="send.php" id="theform" name="theform"&gt; &lt;input type="text" name="firstname" id="firstname" value="First Name" onFocus="this.value=''" class="yourinfo" &gt;&lt;br/&gt; &lt;input type="text" name="lastname" id="lastname" value="Last Name" onFocus="this.value=''" class="yourinfo"&gt;&lt;br/&gt; &lt;input type="text" name="email" id="email" value="Email Address" onFocus="this.value=''" class="yourinfo"&gt;&lt;br/&gt; &lt;div id="datepicker"&gt;&lt;/div&gt; &lt;input type="hidden" name="date" id="date"&gt; &lt;input type="image" src="images/sbmit-button.png" name="submit" height="49" width="190" id="submit" value="submit" style="margin-top:10px; margin-left:-2px;" &gt; &lt;/form&gt; </code></pre> <hr> <p><strong>heres the javascript</strong></p> <pre><code>$(document).ready(function(){ // Place ID's of all required fields here. required = ["firstname", "lastname", "email"]; // If using an ID other than #email or #error then replace it here email = $("#email"); errornotice = $("#error"); // The text to show up within a field when it is incorrect emptyerror = "Please fill out this field."; emailerror = "Please enter a valid e-mail."; $("#theform").submit(function(){ //Validate required fields for (i=0;i&lt;required.length;i++) { var input = $('#'+required[i]); if ((input.val() == "") || (input.val() == emptyerror)) { input.addClass("needsfilled"); input.val(emptyerror); errornotice.fadeIn(750); } else { input.removeClass("needsfilled"); } } // Validate the e-mail. if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) { email.addClass("needsfilled"); email.val(emailerror); } //if any inputs on the page have the class 'needsfilled' the form will not submit if ($(":input").hasClass("needsfilled")) { return false; } else { errornotice.hide(); return true; } }); // Clears any fields in the form when the user clicks on them $(":input").focus(function(){ if ($(this).hasClass("needsfilled") ) { $(this).val(""); $(this).removeClass("needsfilled"); } }); }); </code></pre> <hr> <p><strong>im also linking to a jquery file:</strong></p> <pre><code> &lt;script type="text/javascript" src="js/jquery-1.5.1.min.js"&gt;&lt;/script&gt; </code></pre> <hr> <p>ive tested it on its own and it seems to work but something seems to be over riding it and skipping past the validation in this page</p> <p>==================================================================================</p> <p>i still not working... basicallly do u think it might have something to do with the jquery UI datepicker that im also using with the form?? ive not included that in the form validation as i only wanted to make sure the firstname, lastname and email was filled out</p> <p>i have this included in my form page:</p> <pre><code>&lt;script&gt; $(function() { $("#datepicker").datepicker({ altField: '#date' }); $('#submit').click(function() { $('#output').html($('form').serialize()); }); }); &lt;/script&gt; </code></pre> <p>would this be having an effect of it submitting even though there are no values in the fields?</p> <p>something is definatley overriding the validation and submitting it</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload