Javascript Help: Passing data from one form to another.
I'm trying to make a form with Captcha.
But since i'm using a third party email form like Saleforce.com, I can't use my captcha script because the code needs to be inserted in the form action.
sample:
Code:
<form action="form.php" method="post">
i need to add the captcha script in the php file which is the action of the form.
but in my case, my form action is:
Code:
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
so i can't insert the php code for the captcha to work.
Which is i have another idea, I need to find a script that can pass a data from one form to another.
which is after a user submits the first form, the form values will be pass to another page with a form.
sample form:
Code:
http://alfren24.info/captchaform/sample/
My Idea is i will insert the captcha php code in the form target which is step3.php so that the captcha will work and the data which is submitted by the user will be passed in the step3.php page then i will use a autosubmit form script so that it will be automatically submitted.
but there's a problem with the javascript code.
The script won't work if i add a method in my form code.
sample:
Code:
<form action="step3.php method="post">
and the captcha script won't work if my form code has no method.
here's the link to my form with captcha:
Code:
http://alfren24.info/captchaform/index.php
This is my one and only problem.
any help will be appreciated.
here's my form code in the first form page:
Code:
<form action="step3.php" method="post">
<table>
<tr><td colspan=2><center></center></td></tr>
<tr><td>Name:</td><td><input type="text" name="name" value="" size="20"></td></tr>
<tr><td>Email:</td><td><input type="text" name="from" value="" size="20"></td></tr>
<tr><td><img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" /></td>
<td><input type="text" name="captcha_code" size="10" maxlength="6" /></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>
and the javascript and captcha php code in the second page:
Code:
<?php session_start();
include_once $_SERVER['DOCUMENT_ROOT'] . '/captchaform/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
// or you can do something really basic like this
die('The code you entered was incorrect. Go back and try again.');
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form action="step4.php" method="post" name="myForm">
<tr><td>Name:</td><td><input type="text" name="name" value="" size="20"></td></tr>
<tr><td>Email:</td><td><input type="text" name="from" value="" size="20"></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td></tr>
</form>
<SCRIPT LANGUAGE="JavaScript"><!--
function getParm(string,parm) {
// returns value of parm from string
var startPos = string.indexOf(parm + "=");
if (startPos > -1) {
startPos = startPos + parm.length + 1;
var endPos = string.indexOf("&",startPos);
if (endPos == -1)
endPos = string.length;
return unescape(string.substring(startPos,endPos));
}
return '';
}
var passed = location.search.substring(1);
document.myForm.name.value = getParm(passed,'name');
document.myForm.from.value = getParm(passed,'from');
function replace(string,text,by) {
// Replaces text with by in string
var i = string.indexOf(text), newstr = '';
if ((!i) || (i == -1))
return string;
newstr += string.substring(0,i) + by;
if (i+text.length < string.length)
newstr += replace(string.substring(i+text.length,string.length),text,by);
return newstr;
}
//--></SCRIPT>
</body>
</html>