Solved

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

Posted on 2011-09-28
7
213 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Technology Partners: 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!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

756 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