Solved

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

Posted on 2011-09-28
7
208 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Nura111
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Can it be a Permission issue?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now