Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

a problem in sending the form varaibles using jquery .post()

Posted on 2011-09-28
7
Medium Priority
?
217 Views
Last Modified: 2012-05-12
Hi all, Im trying to sumbit a Form using Jquery using .post()
the problem is that not all the forms field are generating (when using serialize)

(when im checking the results using the alert its showing:flag=on&id=12024&email=1andonly%40gmail.com) so only the 3 input field are generating)


$("#"+popup_form_id).submit(function(e) {
                         //   alert("Hello world!");
							//fElement.attr('flag','1');
							e.preventDefault();
						//"mark" the input name =flag as spam 
						    $(":hidden[name='flag']","#"+popup_form_id).val("on");
							fElement.toggle();
							//$.ajax(
							alert($(this).serialize());
							$.post(url,$(this).serialize());
								
							
					})

Open in new window

<form id = "popup_form_{$row['id']}"  action ="" method ="post" style="background-color:white; border:2px solid blue;padding:4px; width:250px; display :none; position:absolute"  onsubmit = "return false;">

			<input type ="hidden" name="flag" value = "no" >

			<input type="hidden" name="id" value ="{$row['id']}">

			<input type="hidden" name ="email" value ="{$row['email_address']}">

			<input type="submit" name="spamIt" value="SpamIt"  style="margin-right:15px;">

			<input type="button" value="Close" onclick="closePopup()"/>

			

			</form>

    </tr>

Open in new window

0
Comment
Question by:Nura111
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
MacAnthony earned 2000 total points
ID: 36719437
From the serialize documentation:

No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute.

So the submit button won't be serialized since it's not submitting via that, and the input button doesn't since it does not contain a 'name' attribute.
0
 

Author Comment

by:Nura111
ID: 36719515
ok in the page im sending the request is the following code so what can Is end to .post in order for it to work? or thats is not how Im suppose to do that?

if (isset($_POST['spamIt']))
if (isset($_POST['spamIt'])){
		//echo "try";
		 $id = $_POST['id'];
		 $email = $_POST['email'];

		 $sql= BaseModel::getSqlObject();
		
		 $query = "SELECT * FROM BlackList WHERE email_address = '$email'";	
	     
		if (($result=$sql->Query($query)) === FALSE)
           die(ShowError("Server Query Error"));
		$num = $result->num_rows;
	   
	//check if email is not already exist in BlackList
	    if ($result->num_rows == 0){
   			 $insert_query = "INSERT INTO BlackList(email_address) VALUES ('$email')";
			 
			 if (($result=$sql->Query($insert_query)) === FALSE)
           	die(ShowError("Server Insert Query Error"));
		}
		
		$insert_query =	"UPDATE ServiceRequests SET spam = 1 WHERE id = '$id'";
		if (($result=$sql->Query($insert_query)) === FALSE)
           	die(ShowError("Server Insert Query Error service"));


			die ("ok");
         
	
		
 
		
		}

Open in new window

0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36719614
You could make another hidden field with the name and value of spamIt in the form and that one should submit. The other option would be to change the current field from a submit button to a type "button" and have an onclick event of onclick="this.form.submit();".

I haven't tested either of those, but I think they should both work.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Nura111
ID: 36719683
ok Im getting form the post request the following error 500 Internal Server Error
            107ms

any idea whats is happening?
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720088
I'm not sure what would be causing the 500 error, but it shouldn't be the call itself from what you've provided.
0
 

Author Comment

by:Nura111
ID: 36720093
I also attched the code in the php script its not long can you take a look? I cant figure it out
0
 

Author Comment

by:Nura111
ID: 36720224
Can it be a Permission issue?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question