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?
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script type='text/javascript'>
- $(function() {
- $('#feedbackgiven').submit(function(event) {
- event.preventDefault()
-
- var name1 = $('#feedbackgiven [name="name"]').val();
- var email1 = $('#feedbackgiven [name="email"]').val();
- var feedback_1 = $('#feedbackgiven [name="feedback"]').val();
- $.ajax({type: 'POST', url: 'submit-feedback.php', cache: false, timeout: 10000,
- data: {name_sub: name1, email_sub: email1, feedback_sub:feedback_1},
- success: function() {
- alert('Your feedback has been recived');
- },
- error: function() {
- alert('There was a problom');
- },
- });
- });
- });
- </script>
-
- <span>Send us your feedback</span>
- <form id="feedbackgiven">
- <input name="name" value="Your name" onfocus="this.value=''"><br />
- <input name="email" value="Your E-mail" onfocus="this.value=''"><br />
- <textarea name="feedback" cols="45" rows="10"></textarea><br />
- <input type="submit" value="Send Feedback">
- </form><br />
- </div>