This is my old code...
[HTML]<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>[/HTML]
it passed some form data onto my sendmail.php script and it worked just dandy. 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 used to reside.
Now, when 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 form/page:
[HTML]<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>[/HTML]
It no worky. With the old form code in the sidebar, it submits and process. With new sidebar (text + link) the javascript doesn't "fire off"
I'm sure it's something dumb.. .what am I missing?
Posts
Also, why did you switch the code from using labels and inputs... to using tables, labels, and inputs -.-
I just tried after making sure my functions were properly named and it worked!
have I mentioned that I'm not really a programmer and I'm doing this mostly through extensive trial and error and google-fu.
So how would I go about tying a validation script to this? Most examples I've googled use onSubmit to call on their validate function. Would I need to do that, but make an conditional rule that submits if true and shows the error if false?
As for your second question about the tables: that's strictly for formatting. It's old-school and ugly code-wise, but it works best for making things appear in the proper row/column in this form.
But you should really have server-side (PHP) validation as well, as JS validation can be bypassed.
EDIT: Tables are not for formatting. :P