0

I have this small test page trying to mess around and figure out PHP code, from what I understand, after filling the forms and hitting submit, something should happen. Depending on what you entered.

<!DOCTYPE html> <html> <head> <title>PHP Testing Page</title> </head> <body> <?php echo "Testing Page, working great!\n"; $theDate = date("M-d-Y "); echo "Today is " . $theDate; $email1 = $_POST['email1']; $email2 = $_POST['email2']; function checkEmail() { $email1 = $_POST['email1']; $email2 = $_POST['email2']; echo $email1; echo $email2; if($email1==$email2) { echo "\nE-Mail Addresses match."; } else { echo "\nCheck to make sure your E-Mails match"; } } ?> <form name="checkingEmail" action="." method="post"> E-Mail: <input type="text" name="email1" value="E-Mail Here" /> <br /> Retype E-Mail: <input type="text" name="email2" value="Confirm E-Mail" /> <br /> <input type="button" value="Submit" onClick="checkEmail()"> </form> </body> </html> 

After the forms are filled (via visiting page) and the Submit button is clicked, nothing happens. Can someone explain please?

********EDIT******FIXED** Found a work around! No functions, works like a charm.

<!DOCTYPE html> <html> <head> <title>PHP Testing Page</title> </head> <body> <?php echo "Testing Page, working great!\n"; $theDate = date("M-d-Y "); echo "Today is " . $theDate; ?> <form name="checkingEmail" action="test.php" method="post"> E-Mail: <input type="text" name="email1" value="E-Mail Here" /> <br /> Retype E-Mail: <input type="text" name="email2" value="Confirm E-Mail" /> <br /> <input type="submit" value="Submit"> </form> <?php $email1 = $_POST["email1"]; $email2 = $_POST["email2"]; if($email2==null) { /*I believe this just stops it from checking the rest of the conditions, that way it won't echo anything until someones enters valid (non-null) input*/ $email2 = "notnull"; } else if($email1==$email2) { echo "Good Job."; } else { echo "Failure to comply."; } ?> </body> 

I have the check outside of a function, so I don't have to call it or anything like that. Also, with the first if statement, if $email2 is null (When they first load it) it will simply change $email2 to "notnull" and stop checking statements because it found a valid one. (Not 100%)

2 Answers 2

4

Where is your submit button ?

<input type="button" value="Submit" onClick="checkEmail()"> ^ 

The type should be submit

As mentioned on this answer comments, you can't call a php function from javascript.

When you do it you'll call checkEmail from a javascript, which isn't defined.
So, you'll get the following error:

Uncaught ReferenceError: checkEmail is not defined 
Sign up to request clarification or add additional context in comments.

5 Comments

You didn't mention that he's trying to call a php function from javascript?
@SamDufel Let's do it step by step ;)
Oh silly me! Thank you. Also, on the click I am being sent to my home page. I would not like that... What about this function now?
@TheWalkingPacifist You have to create a javascript function that validate it. You can simple google it. There're many demos that show how to do it.
Ugh, this is too much for one day. I'll look for it tomorrow. If you could post a helpful link or something whilst I'm gone that would be great.
0

type should be submit;

If you change it to the submit and then run it, it should be fine. You should use submit type with Form elements.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.