Making some text fields required.

Making some text fields required.

I am working on a new feedback form for my site. I have the basics working fine, the form can be submitted and the data is handled just the way its supposed to. I'm looking to make it so a name and the feedback is required but the email is not. I would also like to add a human check to this. I'm moving over from php and had a remove the text as my human check. Last question, is this the best way to be doing this?

  1. <script src="http://code.jquery.com/jquery-latest.js"></script>
  2. <script type='text/javascript'>
  3. $(function() {
  4.     $('#feedbackgiven').submit(function(event) {
  5.            event.preventDefault()
  6.            
  7.           var name1 = $('#feedbackgiven [name="name"]').val();
  8. var email1 = $('#feedbackgiven [name="email"]').val();
  9. var feedback_1 = $('#feedbackgiven [name="feedback"]').val();
  10.            $.ajax({type: 'POST', url: 'submit-feedback.php', cache: false, timeout: 10000,
  11.                  data: {name_sub: name1, email_sub: email1, feedback_sub:feedback_1},
  12.                  success: function() {
  13.                        alert('Your feedback has been recived');
  14.                  },
  15.                  error: function() {
  16.                        alert('There was a problom');
  17.                  },
  18.            });
  19.      });
  20. });

  21. </script>
  22. <span>Send us your feedback</span>
  23. <form id="feedbackgiven">
  24. <input name="name" value="Your name" onfocus="this.value=''"><br />
  25. <input name="email" value="Your E-mail" onfocus="this.value=''"><br />
  26. <textarea name="feedback" cols="45" rows="10"></textarea><br />
  27. <input type="submit" value="Send Feedback">
  28. </form><br />
  29. </div>