1

Need quick help, if anyone can...

I have a quite simple html one page with form and I'm trying to validate it with php (check blanks and verify email) for some reason something going wrong and it doesn't show me anything on action form

anyone have any idea? will really help me a lot. the icons present the obvious (the text is hebrew) (if someone knows how to validate phone, bless you as well)

the html:

<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
    <title>Safari Company</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <script src="js/script.js"></script>
</head>

<body>

    <div id="top-wrapper">
        <div id="top-background">
            <p class="image-text">.אפריקה. נקודת מבט חדשה</p>
            <p class="credit-english">Ziv Koren</p>
        </div>
    </div>

    <div id="costumer-wrapper">
        <div id="info-for-client">
            <p class="secondary-text">הדרך לאפריקה מתחילה בטיסה ישירה לטנזניה</p>
            <p class="offer-text">פסח 2015 <span>|</span> 9 ימים מלאים</p>
            <p class="ratz-border-above">ספארי קומפני בטיסת (סאנדור) אל-על ישירה לטנזניה וחזרה ישירות מזנזיבר. מבחר תוכניות ספארי מותאמות באופן אישי.</p>
            <p class="strong">תמיד אמרתם שפעם תעשו את זה. עכשיו זה הזמן</p>
            <p class="secondary-text">למידע נוסף, התאמת ספארי אישי </br> והזמנות 03-5617021</p>
        </div>


            <form  method="post" action="confirmation.php" name="myForm" onsubmit="return validate();">
                <input type="text" class="name" name="Name" placeholder="שם">
                <input type="text" class="email" name="Email" placeholder="דוא״ל" >
                <input type="text" class="phone" name="Phone" placeholder="טלפון" >
                <textarea placeholder="הערות"></textarea>
                <input type="checkbox" > ארצה לקבל עדכונים וחדשות
                <button type="submit"> שלח</button>
            </form>

        <p class="hebrew-credit">זהות ושפה - מוסנזון פורת</p>

    </div>

    <div id="bottom-background">
        <div id="bottom-image"> </div>
        <p class="credit-english"></p>
    </div>

    <div id="footer-wrapper">
        <footer>
            <p>ספארי, בשפה הסווהילית, פירושו מסע, בשפה שלנו, מסע פירושו יציאה לדרך של גילויים חדשים, מראות, ריחות, טעמים.</br>
                תחושה שאין דומה לה. לגלות את אפריקה, בכל פעם מחדש, כבר 20 שנה. נשמח להיות הדרך שלכם לאפריקה.</p>
            <p class="adress-border-above"> סעדיה גאון 24, תל אביב טל. 03-5617021 פקס. 15335468614 <span> | www.safaricompany.co.il | info@safaricompany.co.il</span></p>
            <a href="#"><img src="images/logo.png"></a>
        </footer>
    </div>

</body>
<script>
     function validate(){

     if( document.myForm.Name.value == "" )
     {
        alert( "Please provide your name" );
        document.myForm.Name.focus() ;
        return false;
     }

     if( document.myForm.Email.value == "" )
     {
        alert( "Please provide your Email" );
        document.myForm.Email.focus() ;
        return false;
     }

     if( document.myForm.Phone.value == "" )
     {
        alert( "Please provide your Phone" );
        document.myForm.Phone.focus() ;
        return false;
     }

     return true;
  }
  </script>

</html>

the php:(confirmation.php)

<?php 
if($_SERVER["REQUEST_METHOD"] == "POST"){

    $name = trim($_POST["Name"]);
    $email = trim($_POST["Email"]);
    $phone = trim($_POST["Phone"]);

    if( $name == "" || $email=="" || $phone==""){
        echo "Please fill name, email and phone";
        exit;
    }


    require_once("Inc/phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();
    if(!$mail -> ValidateAddress($email)){
        echo "You must specify a valid email.";
        exit;
    }

?>


<html>
<body>

Welcome <?php echo $_POST["Name"]; ?><br>
Your email address is: <?php echo $_POST["Email"]; ?>

</body>
</html>
Yehuda Menahem
  • 255
  • 1
  • 3
  • 13
  • basic debugging: turn on `error_reporting` and `display_errors` and try again... and where's your javascript `validate()` function? – Marc B Jul 08 '15 at 20:31
  • @MarcB he is validating with php and using javascript without any javascript – Shehary Jul 08 '15 at 20:35
  • I edited and added the javascript. Marc B - I'm really new in php so dont know how even to do debuggin and in a lot of pressure cause I need it urgent.../ : – Yehuda Menahem Jul 08 '15 at 20:38
  • The online debugger shows me: unexpected end in line ..(the final line in php) but I ended it good I think – Yehuda Menahem Jul 08 '15 at 20:56

2 Answers2

1

It probably is overkill to use a custom library just to verify an email address. You could use https://secure.php.net/filter_var with the FILTER_VALIDATE_EMAIL filter. As far as I know, there is no real way of validating phone numbers.

That being said, your PHP error is that you do not close the if statement started on line 2. That causes an unexpected end, as the compiler still wants a closing accolade for your if statement.

EDIT: There is a very good SO answer for validating phone numbers.

Bert Peters
  • 1,505
  • 13
  • 30
0

There are a few things going on with the approach to your script.

Here is what I came up with that works on the script page.

<?php 

if($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = trim($_POST["Name"]);
    $email = trim($_POST["Email"]);
    $phone = trim($_POST["Phone"]);

    if( $name == "" || $email=="" || $phone==""){
        $error = "Please fill name, email and phone";
    }
}
else {
     $error = "ERROR if someone came here directly";
}

?>


<html>
<body>

<?php if(isset($error)): ?>

<p><?php echo $error; ?></p>
<?php else: ?>
Welcome <?php echo $_POST["Name"]; ?><br>
Your email address is: <?php echo $_POST["Email"]; ?>
<?php endif; ?>

</body>
</html>

EDIT: To address the email validation you would use this to check if true or false: This method checks if the email is NOT valid.

if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $emailError = "Invalid email";
}
ja408
  • 798
  • 5
  • 16
  • First of all, thank you all for your comments ja408, thank you a lot! ( : it's working! appreciate a lot – Yehuda Menahem Jul 08 '15 at 21:39
  • No problem. If you feel strongly can you mark my answer as the answer? Thanks! – ja408 Jul 08 '15 at 21:43
  • I added one more comment to the answer to address the email validation. Bert Peters mentioned it in his answer, but I added an example of your code. – ja408 Jul 08 '15 at 21:55