I think this may be able to help. I created my own validation javascript that will check the element for a value and if not it prints a box behind it saying there was an error. It also works for validating emails.
What you would need to do to make it work is include and id and onblur to your input element that you would like validated. For instance if you have an input named firstname you would change the input to:
I would suggest you look in to PHP's empty() and isset() functions, but make sure that you understand the range of empty() before you use it, to make that's what you want.
Well I guess you could do it in the onsubmit and do a ajax request, or you could let it enter the server side file called in the action attribute. If the validation fails there it'd redirect you back to the form.
If i was to use it as server side action would it not reset the form on redirect back, also my form is in a popup box not a page. Hope this makes sense + thank you for the support
You can store the data in the session to fill out the form with the correctly entered data. But if it's in a pop up I would maybe suggest that you go with ajax.
Thank you, what would i use for validation could you please show me an example + the popup is all JavaScript that opens a PHP file. below i have showed the on click function, this opens popupsignup.php and requires a .js file which i also have created.
<?php
if (isset($_POST['submit'])) {
$fistname = trim($_POST['fistname']);
$lastname = trim($_POST['lastname']);
if ((!isset($firstname, $lastname)) || ($firstname == '') || ($lastname == '')) {
print 'You must fill out both firstname and username';
} else {
// Filter all user inputs here and save to the database
}
}
?>
This was just a quick writeup without testing, so please expect that there might be some errors in it
Bookmarks