Note that there are some explanatory texts on larger screens.

plurals
  1. POphp form validation function not working properly
    primarykey
    data
    text
    <p>Hi I need some help please, if its possible.</p> <p>I have created a PHP function that shows the errors of a form server-side validation right below each field. Here are the basic parts:</p> <pre><code>$errors = array(); //check if e-mail is valid if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){ $errors['email'] = "Please give a valid email."; } ..... function display_error($field_name){ global $errors; if($errors[$field_name]){ echo "&lt;span class=\"form_error\"&gt;" . $errors[$field_name] . "&lt;/span&gt;\n"; } } .... &lt;span id="spryEmail"&gt; &lt;label&gt;E-mail *&lt;br /&gt; &lt;input type="text" name="email" id="email" /&gt; &lt;/label&gt; &lt;span class="textfieldRequiredMsg"&gt;Your e-mail is required.&lt;/span&gt;&lt;span class="textfieldInvalidFormatMsg"&gt;Please provide a valid e-mail.&lt;/span&gt;&lt;/span&gt; &lt;?php display_error('email'); ?&gt; </code></pre> <p>When I preview the form on the browser (I temporarly disable javascript), it shows me this:</p> <p><strong>Notice: Undefined index: email in C:.......\functions.php on line 60</strong> , which points to the if statement inside the function. How can I fix this Notice, so that doesn't show up? Note: If I submit the form, the error message show up correctly.</p> <p>2) AS you notice I've also added some Spry validation that validates onblur. I have a captcha field </p> <pre><code>&lt;span id="spryCaptcha"&gt; &lt;label&gt;Security code *&lt;br /&gt; &lt;img src="captcha.php" id="imgCode" /&gt; &lt;input type="text" name="captcha" id="captcha" /&gt; &lt;/label&gt; &lt;span class="textfieldRequiredMsg"&gt;Please type the code you see.&lt;/span&gt;&lt;/span&gt; &lt;?php error_for('captcha'); ?&gt; </code></pre> <p>and what I'd like to make is if the user enters the wrong code the message from the error_for function also to display onblur, before hitting the submit button. How can I make this work?</p> <p>Any help would be appreciated.</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.
    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