I have a page that was used a php include to pull this code into a sidebar div:
<html>
<head>
<script type="text/javascript">
function submitform()
{
document.forms["question_form"].submit();
}
</script>
</head>
<body>
<div style="padding:25px 35px 35px 35px;">
<p class="bb center"><strong>Texty text stuff</strong></p>
</div>
<div id="question_form">
<form id="question_form" method="post" action="sendmail.php" target="_self" onSubmit="return checkemail(this)">
<p>
<label for="name">Your name:</label> <br /> <input type="text" id="name" value="" /><br />
<label for="email">E-mail address:</label> <br /> <input type="text" id="email" value="" /><br />
<label for="phone">Phone</label> <br /> <input type="text" id="phone" value="" /><br />
<label for="question">Questions or Comments</label>
<textarea NAME="comment" id="question"ROWS=150 COLS=150> </textarea>
</p>
<div><a href="javascript: submitform()" class="box_ro3">SUBMIT</a></div>
</form>
</div>
</body>
</html>
it passed the form data onto my sendmail.php script and it works. I get the email with all the form info included.
Then the client decided they wanted a more involved form, so I re-coded it and plugged the form code into a main content div, and put some text and a mailto: link in the sidebar where the old form code reside.
At this point, when I click on the “submit” button, the javascript doesn’t send the form data over to the sendmail script. But, if I drop the old form code back into the sidebar, it does. After much testing of cut/pasting of validation code and other factors, I narrowed it down to this factor: the old form code needs to be in the sidebar. (code trimmed of extraneous stuff)
New contact page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="css/layout.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<script type="text/javascript">
function submitform()
{
document.forms["question_form"].submit();
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<h1 class="ital">Page Title</h1>
</div>
<div id="shell">
<h3>Contact us:</h3>
<p>For more information ... blah blah blah... fill out the form below.</p>
<!--snipped: misc html info and a google maps embed-->
</div><!--shell close-->
<div id="formbox">
<table align="center" cellpadding="0" cellspacing="0" width="100%">
<form id="question_form" method="post" action="sendmail.php" target="_self" onSubmit="return checkEmail(this)">
<tr><td align="left" width="200" colspan="3">
<label class="desc top" >Full name: </label>
<input name="name" class="element text med" type="text" maxlength="75" size="180" tabindex=1 />
</td>
<!--snipped: big hunk of form code that's not relevant...-->
</tr>
<tr><td align="right" colspan="5">
<a href="javascript: submitform()" class="box_ro1">SUBMIT</a>
</td></tr>
</form>
</table>
</div> <!-- formbox closed -->
<div id="nav">
<?php
include("nav_main.php")
?>
</div>
<div id="login">
<?php
include ("login.php");
?>
</div>
<div id="right">
<?php
include ("sidebar.php"); <!-- this is where the old form code resided-->
?>
</div>
<?php
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
?>
</div> <!--wrapper close-->
</body>
</html>
As you can probably tell from my clunky code, I’m not adept at either javascript of php - I’m learning as I go.