Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP contact form, am I doing it wrong?
    primarykey
    data
    text
    <p>I'm learning PHP and I'm trying to write a simple email script. I have a function (checkEmpty) to check if all the forms are filled in and if the email adress is valid (isEmailValid). I'm not sure how to return true checkEmpty funciton. Here's my code:</p> <p>When the submit button is clicked:</p> <pre><code>if (isset($_POST['submit'])) { //INSERT FORM VALUES INTO AN ARRAY $field = array ('name' =&gt; $_POST['name'], 'email' =&gt; $_POST['email'], 'message' =&gt; $_POST['message']); //CONVERT ARRAY KEYS TO VARIABLE NAMES extract ($field); checkEmpty($name, $email, $message); function checkEmpty($name, $email, $message) { global $name_error; global $mail_error; global $message_error; //CHECK IF NAME FIELD IS EMPTY if (isset($name) === true &amp;&amp; empty($name) === true) { $name_error = "&lt;span class='error_text'&gt;* Please enter your name&lt;/span&gt;"; } //CHECK IF EMAIL IS EMPTY if (isset($email) === true &amp;&amp; empty($email) === true) { $mail_error = "&lt;span class='error_text'&gt;* Please enter your email address&lt;/span&gt;"; //AND IF IT ISN'T EMPTY CHECK IF IT IS A VALID ONE } elseif (!isValidEmail($email)) { $mail_error = "&lt;span class='error_text'&gt; * Please enter a valid email&lt;/span&gt;"; } //CHECK IF MESSAGE IS EMPTY if (isset($message) === true &amp;&amp; empty($message) === true) { $message_error = "&lt;span class='error_text'&gt;* Please enter your message&lt;/span&gt;"; } } // This function tests whether the email address is valid function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)) { return true; } else { return false; } } </code></pre> <p>I know I shouldn't be using globals in the function, I don't know an alternative. The error messages are display beside each form element.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload