开发者

Submit data twice on one page

I asked this question but had so much crap code that I have broken it down to the minimum ammount of code this time. Form page sends data to confirm page.

Confirm page echos data to user so they can double check it. then if they click "submit" it reloads the same page sends an email to me then it updates the url for the forms action and a little javascript submits the form again without the user knowing it since $url is not empty. Everything is working but the javascript is not doing its part. the page just sits there and I can see the javascript in the page source so its there.

Form page:

<form action="test.php" method="post">
    Name: <input type="text" name="name" value=""/>
    <input type="submit" name="send" value="send"/>
</form>

confirm page:

<?
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

$url = '';
    if (isset($_POST['send']))
        {
            $data = $_POST['name'];
        }else{ 
            echo "SEND is not Set";
 开发者_开发技巧       }


    if (isset($_POST['submit']))
        {
            $data = $_POST['data'];
            $my_message = ' TEST DATA:<br/><br/>Child Name'. $data .'';
            $subject = 'Mike TEST';
            $headers = "From: mrawers@xxxx.com\r\n";
            $headers .= "Reply-To: mrawers@xxxx.com\r\n";
            $headers .= "Content-type: text/html\r\n";

            $url = "https://www.paypal.com/cgi-bin/webscr";

            mail("mike.rawers@xxxx.com",$my_message,$subject,$headers);
        }else{ 
            echo "SUBMIT is not Set";
        }
?>
<html>
<head>
</head>

<body>

<form action="<? echo $url; ?>" method="post">
    Name:   <? echo $data; ?><input type="hidden" name="data" value="<? echo $data; ?>"/><br/><br/>
<input type="submit" value="submit" name="submit">
</form>
<?
if ($url != "") {
?>
<script language="javascript">
document.forms[0].submit();
</script>
<?
}else{ echo "URL NOT SET";}
?>
</body>
</html>


Delete this line of code than you'll get what you want:

<input type="submit" value="submit" name="submit">

WHY?

That's because of the "name". The input element with the name "submit" is conflict with the submit function. You wanted to call the "submit" function, but the broswer just got the "submit" element.

You can take a try of this:

alert(document.forms[0].submit);

It's a element.

Btw, You can excute the "submit" function without the "submit" element.


Rather than re-posting the data to another URL why not use a cURL object in the PHP to send it after emailing?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜