Page 1 of 1

Dealing with POST data

Posted: Thu Feb 23, 2012 8:14 am
by spacebiscuit
Hi,

I'm using a simple bit of javascript to popup a prompt for user input which is posted back to a php script.

The HTML form is as follows:

Code: Select all

<form action="test.php" method="post" name="contactForm" id="contactForm">
  <p><input name="customerid" id="customerid" type="text" size="30" value="Input Your Customer ID" /></p>
  <p><input type="submit" id="submit" name="submit" value="Send" /></p>
</form>
As you can see the data is posted back to test.php

In my javascript I have the following which I thought determined the data sent back and to where it is sent?

Code: Select all

$.ajax({
	type: "POST",
	url: "test.php",
	data: "customerid=" + customerid,
	error: function() {
		$('.error').hide();
		$('#sendError').slideDown('slow');
	   },
	success: function () {
	       $('.error').hide();
	       $('.success').slideDown('slow');
               $('form#contactForm').fadeOut('slow');
	}				
});
However if I change the 'url', 'type' and 'data' the data is still sent to the page. It seems that the only factor determining this is the html form?

Thanks.

Re: Dealing with POST data

Posted: Thu Feb 23, 2012 8:31 am
by spacebiscuit
It seems using $_SERVER['PHP_SELF'] by passes anything the the jquery attempts to setup.

Is this bad practice?

Re: Dealing with POST data

Posted: Thu Feb 23, 2012 10:34 pm
by Gopesh
Hi,Try without using the action="test.php" in the form tag.