bwakad Posted August 31, 2014 Share Posted August 31, 2014 Hello, For my form I use the standard HTML5 (not echo out) and fields are required in combination with a pattern. I have not a clue if this is supported in all browsers. And I do not know if these validations can be by passed. But hey, we have PW to check submitted fields! The form post to the same page. So if($input->post->username) is excisting in PW while is should be new, I would like to see a message saying that, in stead of returning an empty form with no message. I have tried to search through the forums, used Google as well, but could not find a result since "error" is not just related to a form. I really could use an example how to retrieve errors saying WHAT was not good. Or is everyone using jquery for that? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 1, 2014 Share Posted September 1, 2014 I have not a clue if this is supported in all browsers. And I do not know if these validations can be by passed. It's not reliable, old browsers don't recognise it, but the good thing, you can use the same patterns in PHP. Thats how the patterns work in ProcesWire. To show errors you could create an empty array named $errors an push every found error to that array. like $errors[] = 'Gebruikersnaam is al in gebruik.'; Then for the logic, you can count($errors) and route the page to what you want to show. Link to comment Share on other sites More sharing options...
bwakad Posted September 1, 2014 Author Share Posted September 1, 2014 Thanks, I did it like code below. Had to set (novalidate in my form tag) to test. - EDIT - see also topic SessionLoginThrottle Now, with an empty field is does not matter. But if I check on username (taken), or values based on pregmatch, these values are not sanitized until all is good. Those could be a problem. Should I move the sanitize, or do I use a double sanitize ? Don't know if PW allows double sanitize... if ($input->post->submit_registration) { $errorMessage = ""; // check field and add message to variable if (empty($input->post->myfield) ) { $errorMessage .= "<li><b>myfield</b> is empty.</li>"; } if ( empty($errorMessage) ) { // form details are okay, do my thing } } // before I display the form if ( !empty($errorMessage)) { echo "<p>There was an error with your form:</p><ul>" . $errorMessage . "</ul>"; } // start form here <form action='./' method='post' id='someid' novalidate> // field, and retrieve invalid value back <input type='text' name='myfield' value='<?php echo $input->post->myfield; ?>' id='myfield' /> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now