简体   繁体   中英

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(); } } ";

I have a regular button calling this function. emailconfirm is a text input.
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.

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. Now all I have to do is copy + paste that into the emailconfirm field and I'm in.

You haven't defined the form variable anywhere; saying form.submit() isn't going to get very far. Assuming form name of "frm" or something, put something in the likes of

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

earlier in your code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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