Jump to content

Form Submit


Manny

Recommended Posts

I'm currently trying to run a poll service that has 11 options to select from. Upon submitting the form, it uses jQuery to hide the form and display a message thanking the user for voting.I have been using the tutorial on the following website:http://www.ryancoughlin.com/2008/11/04/use...to-submit-form/Below is some of the code that I have used: The name of my radio button is "option".form.html

<script type="text/javascript">	  $(document).ready(function() {		$("form#vote").submit(function() {		// we want to store the values from the form input box, then send via ajax below		var option	 = $(\'#option\').attr(\'value\');						$.ajax({				type: "POST",				url: "submit.php",				data: "option="+ option,				success: function(){					$(\'div#pots\').hide();					//$(\'form#vote :input\').val("");					$(\'div.potssuccess\').fadeIn();				}			});		return false;		});	  });	</script>

I believe the problem is something to do with this line:

data: "option="+ option,

This is my PHP query:submit.php

UPDATE `poll_options` SET `Votes` = (`Votes` + 1) WHERE `OptionID` = '" . $_POST['option'] . "';

The form seems to be submitting fine but then when I go to check the results in my database, none of the votes are registering. I am developing in Firefox so as yet, no cross-browser compatibility testing has been conducted.

Link to comment
Share on other sites

Check for errors in the PHP script, if you're debugging an ajax script you can either use a tool like Firebug and check the response from the server, or have PHP send errors to a log file, or build a form that submits normally instead of through ajax. If you can't tell if the PHP is running, then find that out first. If you're not seeing any PHP errors, then print out the SQL query to see what you're telling the database to do.

Link to comment
Share on other sites

I commented out the Javascript to see if the form submitted with PHP alone and it did.So I did a little more research into how to work with radio buttons in jQuery and stumbled upon this page:http://www.thewhyandthehow.com/jquery-solu...o-button-value/In the end I replaced this:

var option	 = $(\'#option\').attr(\'value\');

With this:

var option	 = $(\'form#vote input:radio:checked\').attr(\'value\');

It works in Firefox, but I'm yet to test in other browsers. Hopefully I don't come across any more problems.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...