I've got my head around the why and what, can't seem to construct the how:
My form is a single textbox submitting data to database & all results then viewed publicly. Which runs flawlessly.
Now I need to validate, when submitted, that the user has:
Created the proper expression: /^[0-9]{3}[\- ]?[0-9]{3}[\- ]?[0-9]{3}$/; (example xxx-xxx-xxx)
Checked database for duplicate entry and accepted or denied addition
I can't seem to put that all together and any help would be fantastic. I'm like right there dangit.😉
My form is a single textbox submitting data to database & all results then viewed publicly. Which runs flawlessly.
Now I need to validate, when submitted, that the user has:
Created the proper expression: /^[0-9]{3}[\- ]?[0-9]{3}[\- ]?[0-9]{3}$/; (example xxx-xxx-xxx)
Checked database for duplicate entry and accepted or denied addition
I can't seem to put that all together and any help would be fantastic. I'm like right there dangit.😉
Hi dgraham,
You can do this either with JavaScript (plus AJAX) in the form itself before submission and/or in the server-side validation box after submission.
The JavaScript validation of the format can be done with a custom LiveValidation; the Database check needs Ajax - there are examples of both in the forums here.
Bob
You can do this either with JavaScript (plus AJAX) in the form itself before submission and/or in the server-side validation box after submission.
The JavaScript validation of the format can be done with a custom LiveValidation; the Database check needs Ajax - there are examples of both in the forums here.
Bob
thanks GreyHead, put me on the right track!
Got the validation down. The DB check for dupes seems to be the tougher nut. Looking...
Got the validation down. The DB check for dupes seems to be the tougher nut. Looking...
Hi dgraham,
Here's a snippet from a development version of the Joomla Registration plugin. It's the code to check an AJAX query for a duplicate username. You can see here the kind of MySQL query that you will need.
Bob
Here's a snippet from a development version of the Joomla Registration plugin. It's the code to check an AJAX query for a duplicate username. You can see here the kind of MySQL query that you will need.
$json = stripslashes($_POST['json']);
$json = json_decode($json);
if ( isset($json->username) ) {
$username = strtolower(trim($json->username));
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`username`) = ".$db->quote($username).";";
$db->setQuery($query);
$response = (bool) !$db->loadResult();
$response = array('username_ok' => $response );
echo json_encode($response);
Bob
This topic is locked and no more replies can be posted.