Jump to content

Clear POST values


RIRedinPA

Recommended Posts

I think this is what I want to do but maybe I am approaching this wrong.

 

I have a large form which can be either saved (data is stored in a mysql db and confirmation emails sent just to user) or submitted (data is also stored in a db but emails are sent to recipient list). In my form I am using images for the save and submit buttons. The action of the form loads the current page and variables are sent via POST.

 

I then check to see if the image button x coordinates have been passed along with the POST array

 

if ($_POST['btn_submit_x'] > 0) { 
	include "lib/submit.php";  
} else if ($_POST['btn_save_x'] > 0) { 
	include "lib/save.php";
} else { 
	echo "Messages:";
}

 

and then load the appropriate include file to do the related action (save or submit). Problem is that when I click refresh the page is retaining the x coordinates of the image button and saving a new copy of the form.

 

The save process is to validate that the user has entered a name and a few other fields, check the db to see if there are any tables with the user last name and today's date and then assign a table name based on that (lastname_date_sequentialnumber), create the table and dump their info from the form into it then send out a confirmation email.

 

What I want to do after this process is clear just the x-coordinates (if they exists) of the image buttons or make their value less than 0.

 

How would I do that?

Link to comment
https://forums.phpfreaks.com/topic/86183-clear-post-values/
Share on other sites

If you literally want to clear the post values, you'd just unset them.

 

unset($_POST['var1']);

 

Thanks, I think that's what I need. Well I also need motivation to want to finish this today and I lack it and it's snowing so I'm off to play and will give this a stab in the morning!  ;D

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/86183-clear-post-values/#findComment-440167
Share on other sites

If it works can hit "Topic Solved"  ;)

 

Thank you!

 

Didn't work, or didn't work the way I wanted. I decided I can achieve what I want to do using AJAX and PHP...

 

...and so here's my new question...

 

My AJAX test code is working except it is not returning a value for the XMLHttpRequest property responseText.

 

Here's what I am doing:

 

Click the save button and that calls an AJAX function, which calls a test php page that simply echoes "This is the new save page" and generates an email to myself. In the Javascript I write the HTTP Response (which I thought should be what I echoed  -->XMLHttpRequest property, responseText, will store the data that a PHP script displays to the browser) to a div named msgBox. The email part works fine, I get a message but nothing gets written back to the page. I've got the error console open in Firefox and the JS looks fine, no errors. I write to the div at the top of the function and that works, so I know I am finding it. Here's my code:

 

Javascript:

function saveRecord()  {
//place divs in an array
var divs=document.getElementsByTagName('div');
//test write to msgBox, it writes the string but then disappears
divs.msgBox.innerHTML= "This is a test";

//ajax [trapping for browsers]
var xmlHttp;
// Firefox, Opera 8.0+, Safari
try {xmlHttp=new XMLHttpRequest();} 
	catch (e) {
  		// Internet Explorer
  		try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
  			catch (e) {
    			try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
    				catch (e) {
      					alert("Your browser does not support AJAX!");
      					return false;
      				}
    		}
  		}

//checking the readystate
xmlHttp.onreadystatechange=function() {
    	if(xmlHttp.readyState==4) {
		//looking to see what newsave.php is returning - it brings back nothing right now, wtf.
		alert(xmlHttp.responseText);
		//the string is written to the page but then disappears
      		divs.msgBox.innerHTML= "This is another test";
      	}
    }
  	xmlHttp.open("POST","newsave.php",true);
  	xmlHttp.send(null);

//same here, the string is written to the page but then disappears, why is it being overwritten by " " ?
divs.msgBox.innerHTML= "This is the third test";
} //end function

 

HTML

<div id="savelink" style="position: absolute; left: 15px; top: 250px; width: 100px; height: 20px; display: block; font: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; padding-left: 0px; padding-top: 3px;"><input type="image" name="btn_save" src="images/btn_save.gif" onClick="saveRecord();"></div>
<div id="msgBox"> </div>

 

PHP

<?php

    //html email
    require_once("../lib/html_mime_mail_2.5/htmlMimeMail.php");
    // Instantiate a new HTML Mime Mail object
    $mail = new htmlMimeMail();
    // Set the sender address
   $mail->setFrom($emailAddress);
    // Set the reply-to address
   $mail->setReturnPath($emailAddress);
    // Set the mail subject
    $mail->setSubject("Merion Direct Mail Order Form | " . $tablename);
    //construct html 
    $html = "This is the email";
    // Create the HTML email
    $mail->setHTML($html, $imagePath);
    // Send the email!
    $mail->send(array("[email protected]"));

    echo "this is the new save page";

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86183-clear-post-values/#findComment-440953
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.