Start New Discussion within our Web Development Community

I am trying to call a .php or .html file to display an input page for emails.

The file ContactDisplay.php contains a <button> to onclick a call to the sendEmail() function which, in turn, sends data to the file ContactEmail.html. The data is retrieved using $_POST and used to populate the <form> contained in ContactEmail.php.

Please see attached file.

The problem is: The form is not displayed nor is the result of print_r($_POST). The 'response' area of FIREBUG shows the total source code of the ContactEmail.php file.

I suspect this is the result of some stupid thing I've done but would appreciate some help in resolving the problem.

Thanks in advance, RP

<!-- 5 March 2012 Instead of showing <form name="mailTo"> populated with values retrieved from ContactDisplay.html
	the Resul as displayed with FIREBUG is just the code for this page.

    ====================  From ContactDisplay.html  onclick="sendMail()" ====================

	<button type="button" class='hov' name="contact" onclick="window.location.href='ContactConnect.html'">View More</button>           
 	<button type="button" class='hov' name="revise"  onclick="window.location.href='ContactRevise.html?dname=' + dispName
 			+ '&reviseId=' + revId">Revise/Add Data</button>
	<button type="button" class='hov' name="email" onclick="sendEmail()">Email</button>   			
 	<button type="button" class='hov' name="delete" onclick="window.location.href='ContactDelete.php?dname=' + dispName + '&reviseId=' + 					revId">Delete</button>  			
//  ====================  common.js  sendMail()  ====================================
//  called from ContactDisplay.html

	function sendEmail() {
		var str=[];
		var var1=$("#Display_Name").val();
		var var2=$("#Home_Email").val();		
		var var3=$("#Work_Email").val();
		var str=('dname='+var1+'&hmail='+var2+'&wmail='+var3);
		$.post("ContactEmail.html", str);

//  ===============  ContactEmail.html  ==============================
	have tried this as .php file also  -->


set_include_path( '../include' );
error_reporting (E_ALL ^ E_NOTICE);

   $hostName = "localhost";
   $databaseName = "contacts";
   $username = "rick";
   $password = "rick";
// From str sent from common.js by $.post("ContactEmail.html", str);


                 "-//W3C//DTD HTML 4.01 Transitional//EN"

	<title>Demo: Using Javascript to send email</title>  

	<div class="header">
  		<h1><img src="../images/AmericanFlag2.png" alt="Company logo" height="90px" />
				Rick and Polly&rsquo;s Contacts</h1>
   		<h3> <span style="padding-left: 140px"> Send Email To: <span style="color: red" > <?php echo $dispName;?></span> </span></h3>

	<div class="wrapper">

		<legend> Emailer</legend>
		<form name="mailTo" method="POST">
		<label for="mailh">Email-Home:</label>
		<input type="text" readonly name="mailh" id="mailh" value="<?php echo $emailHome; ?>"><br></input>
		<label for="mailw">Email-Work:&nbsp; </label>
		<input type="text" readonly name="mailw" id="mailw" value="<?php echo $emailWork; ?>"><br><br></input>
		<label> Mail To:</label><br />
		<input type="radio" name="mail" id="home" value="home" checked="checked">Home<br></input>
		<input type="radio" name="mail" id="work" value="work">Work<br></input>
		<input type="radio" name="mail" id="both" value="both">Both<br><br></input>
		<label for="subject">Subject:</label>
		<input type="text" name="subject" id="subject"><br><br></input>
		<input type="submit" name="submitmail"  value="Submit" >
	</div> <!-- wrapper -->
<!-- Go on to <submit> and do other stuff here -->	

Just posting to a PHP file doesn't show that page. The post function has a callback, which used, gives you the result of the page you post to. Then you can use Javascript/jQuery to do something with that. Have a look at the examples in the manual.

I'm confused (again).

In looking at the manual it givesa number of examples at least two of which imply that you don't need to have a callback function.

Examples: (from manual)

Example: Request the test.php page, but ignore the return results.


Example: Request the test.php page and send some additional data along (while still ignoring the return results).

$.post("test.php", { name: "John", time: "2pm" } );

Example: pass arrays of data to the server (while still ignoring the return results).

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

Example: send form data using ajax requests

$.post("test.php", $("#testform").serialize());

Example: Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

$.post("test.php", function(data) {
alert("Data Loaded: " + data);

Example: Alert out the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).

$.post("test.php", { name: "John", time: "2pm" },
function(data) {
alert("Data Loaded: " + data);

Example: Gets the test.php page content, store it in a XMLHttpResponse object and applies the process() JavaScript function.

$.post("test.php", { name: "John", time: "2pm" },
function(data) {

If I use a callback function like:

function () {

that's supposed to be:
function () {
return true;

Sorry, haven't found out how to edit this post.


Example: Request the test.php page, but ignore the return results.

That is what you do, so anything that is echoed by the PHP file is ignored.

This article has been dead for over six months. Start a new discussion instead.