Solved

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

Posted on 2011-09-28
7
212 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 500 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Suggested Solutions

Title # Comments Views Activity
Dynamic Dropdowns 15 32
jQuery Toggle & Anchor Links 5 42
Autocomplete with Jquery Question 2 19
what is the best Integrated development environment 2 19
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

789 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