简体   繁体   English

PHP与Javascript:电子邮件确认脚本不起作用

[英]PHP with Javascript: Email confirmation script not working

echo " function finishForm() { var answer = confirm('Are you sure these are the teams you want to enter with?'); if (answer) { if(document.getElementByID(emailconfirm).value == ".$_SESSION[Email].") { form.action=\\"esubmit.php\\"; form.submit(); } else { alert('E-mail address do not match'); return false; } } } function restartForm() { var answer = confirm('Are you sure you want to start over?'); if (answer) { form.action=\\"e1.php\\"; form.submit(); } } "; echo“ function finishForm(){var answer =确认('您确定您要与之一起进入的团队吗?'); if(answer){if(document.getElementByID(emailconfirm).value ==”。$ _ SESSION [Email]。“){form.action = \\” esubmit.php \\“; form.submit();} else {alert('电子邮件地址不匹配');返回false;}}}函数restartForm( ){var answer = confirm('您确定要重新开始吗?'); if(answer){form.action = \\“ e1.php \\”; form.submit();}}“;

I have a regular button calling this function. 我有一个常规按钮调用此功能。 emailconfirm is a text input. emailconfirm是文本输入。
I want to confirm that they have chosen the right teams, then check if the email in the session and the email confirmation text match. 我想确认他们选择了正确的团队,然后检查会话中的电子邮件和电子邮件确认文本是否匹配。 If they do match Then i want to submit the form. 如果它们匹配,那么我想提交表格。
If they dont match, I want to alert the user they dont match, and just return to page so user can check emails and then resubmit. 如果它们不匹配,我想提醒用户它们不匹配,然后返回页面,以便用户可以检查电子邮件,然后重新提交。
This script is in my header. 这个脚本在我的头文件中。

EDIT: Haha sorry i submitted one before and it didnt go through, forgot to add my problem!! 编辑:哈哈对不起,我之前提交了一个,但没有通过,忘记添加我的问题了!

When you click the button it comes up with the confirmation, clicking either yes or no doesnt do anything. 当您单击该按钮时,会出现确认消息,单击“是”或“否”不会执行任何操作。 The alert doesnt pop up if they dont match and if they do match it doesnt submit. 如果警报不匹配并且不匹配,则警报不会弹出。 Also it might be good to note I had it without the email confirmation if statement and it worked fine (going to the submit page) 另外也可能要注意,如果没有声明,我没有电子邮件确认,它就可以正常工作(进入提交页面)

You will have to submit the form to php, check if the email is in the session and return to the form if it isn't. 您将必须将表单提交给php,检查电子邮件是否在会话中,如果不是,请返回该表单。

The problem with the way you are doing it now is this: look at the source of the html page and you'll see the required email in the javascript. 您现在的操作方式存在以下问题:查看html页面的源代码,然后您会在javascript中看到所需的电子邮件。 Now all I have to do is copy + paste that into the emailconfirm field and I'm in. 现在,我要做的就是将其复制并粘贴到emailconfirm字段中,然后进入。

You haven't defined the form variable anywhere; 您尚未在任何地方定义form变量; saying form.submit() isn't going to get very far. form.submit()不会走得太远。 Assuming form name of "frm" or something, put something in the likes of 假设表单名称为“ frm”或其他类似名称的内容,

var form = document.getElementById("frm");

earlier in your code. 您的代码前面。

Javascript区分大小写,GetElementByID!= GetElementById,因此应该是固定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM