Link to home
Start Free TrialLog in
Avatar of Nura111
Nura111

asked on

how to sumbit a form in a jquery without loading the result?

Hi All Im trying to submit a form using jquery
and to send the form into a php page that will update the db without sending any result back to the element (I guess using ajax)


fElement.submit(function(e) {
                                          //fElement.attr('flag','1');
                                          e.preventDefault();
                                    //"mark" the input name =flag as spam
                                        $(":hidden[name='flag']","#"+popup_form_id).val("on");
                                          fElement.toggle();
                                          //hoe to post/get the form $.ajax(
                                          
<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" value="SpamIt" name="spamIt" style="margin-right:15px;">

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

			

			</form>

    </tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GregArnott
GregArnott
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"and to send the form into a php page that will update the db"

I was talking about it being a standard javascript handler into a standard PHP receipt page (alas - url: 'myphpsubmitpage.php') that only takes name||value pairs, instead of using an old standard HTML form submit to a PHP page of POST retrieval of each data element to achieve your name||value pairs.

I felt the OP has shown enough aptitude in the code presented to understand classic PHP solutions, and wanted to highlight the jQuery structure alternative.

By all the logic being generated in javascript - data retrieval, validation, sending to server, processing success and completion - makes it not a server side PHP solution.
Avatar of Nura111
Nura111

ASKER

How is the 'formSubmit.php will access the variables (in data)
If I would use POST or GET the script will go to the $_POST array what do I need to do here?

Can I use .post() or .get() to do it? what will be the differences?

Thank you!

Avatar of Nura111

ASKER

Im trying to do




$(popup_form_id).post is not a function
function toggleLeadBody(id) {													
					var fieldName1 = "#spam_"+ id + "_body";
					var fieldName2 = "#sr_" + id + "_body";
					var popup_form_id = "popup_form_" + id;

					var url ="sem_page.php?page=leads&sub=manage";
					 
					var element = $(fieldName2);
                    element.toggle();   
					
					var fElement = $(fieldName1);
				//checking to see if its not been marked as spam	
					if ($(":hidden[name='flag']","#"+popup_form_id).val() =="no"){
					 fElement.toggle();	
					}
    //sumbitting the form			   	    
					fElement.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(url);
							$(popup_form_id).post("sem_page.php?page=leads&sub=manage");
								
							
					})

Open in new window

Avatar of Nura111

ASKER

Oh sorry so Im tring to do it in the way I added it and I keep getting the firebug error:
$(popup_form_id).post is not a function
Avatar of Nura111

ASKER

I didnt use it right sorry its $.post
Avatar of Nura111

ASKER

please help I have a problem with the data im transfering to the page Im using .post()

and sending to a php page (that was originally handling a regular form submit with method post (attached is the )code

isn't the variable of the form is going to be in Post like when you are submitting The form what am I missing here its doesn't work as expected

Thank you!


$("#"+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).serializeArray());
							$.post(url,$(this).serialize());
								
							
					})

Open in new window

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