Click to See Complete Forum and Search --> : form processing help needed
seanpaul
07-10-2003, 04:55 PM
I have written a javascript code to validate my form, but when studying forms I realize that I must post the information to a php file to be processed.
here's the action of the form submit
<form action="processloan.php" onsubmit="return checkdata()" name="form1" method="post">
"checkdata" is a javascript cxommand that validates the form.
then here is the code attached to the button
<input type="submit" value="Submit" name="submit" onClick="javascript:document.form1.Action.value='1'">
what I don't understand is wether or not the javascript action is performed before or after the info is sent to the PHP file. And what exactly do I need to do in "processloan.php" to make the form work?
Any help is appreciated
thanks
First of all, get rid of the onclick in your submit button. You don't need that. Next, the javascript will run when you submit the form. The function checkdata() will retrun either true or false. If it returns true, the form will be submitted to the PHP script specified in your action, if it returns false, the form will not be submitted...
Here is a PHP script I wrote to process forms, if that will help you out. http://forums.webdeveloper.com/showthread.php?s=&threadid=9543#post48748
seanpaul
07-10-2003, 06:59 PM
You can view the code at the following url:
http://www.caillouette.com/SIMC3b/HTML/apply.html
the code for the form begins like this:
<form action="process.php" onsubmit="return checkdata()" name="form1" method="post">
And on the submit button I have this code:
<input type="submit" value="Submit" name="submit" onClick="javascript:document.form1.Action.value='1'">
the javascript validation isn't working and I get the following error Warning: Cannot modify header information - headers already sent by (output started at /usr/home/web/users/a0017855/html/SIMC3b/HTML/process.php:2) in /usr/home/web/users/a0017855/html/SIMC3b/HTML/process.php on line 74
I'm using your php code to process the information. Why isn't the javascript working?
the email comes throughwith the information just fine.
Any advice is greatly appreciated
Please justify having this code in your button:
onClick="java script:document.form1.Action.value='1'"
seanpaul
07-10-2003, 07:41 PM
I still get the following error:
Warning: Cannot modify header information - headers already sent by (output started at /usr/home/web/users/a0017855/html/SIMC3b/HTML/process.php:2) in /usr/home/web/users/a0017855/html/SIMC3b/HTML/process.php on line 74
and my button now has the following code: <input type="submit" value="Submit" name="submit">
But the Javascript isn't working.
I enter just my first name and it sends an email to me with my first name and all the opther labels blank.
you can view the source here:
http://www.caillouette.com/SIMC3b/HTML/apply.html
Thanks for the help
The header error you are getting mean you are trying to set header information after text has been sent to the browser. Perhaps you could post the code in process.php
seanpaul
07-10-2003, 07:54 PM
the code in process is the code from your example.
Here it is in full:
<?PHP
##################################################
#####
# This script is Copyright 2003, Infinity Web Design #
# Written by Ryan Brill - ryan@infinitypages.com #
# All Rights Reserved - Do not remove this notice #
##################################################
#####
## The lines below need to be edited...
###################### Set up the following variables ######################
# #
$to = "sean@caillouette.com"; #set address to send form to
$subject = "Results from your Request Info form"; #set the subject line
$headers = "From: Form Mailer"; #set the from address
$forward = 1; # redirect? 1 : yes
$location = "thankyou.htm"; #set page to redirect to, if 1 is above
# #
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n";
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo ("Thank you for submitting our form. We will get back to you as soon as possible.");
}
?>
Thanks