Hi nic,
I think the easiest way is to create a plugin. I did NOT test this, but it "should" work
Create a folder in oc-content/plugins called "myemail", inside it, create a file called index.php and copy this into it
<?php
/*
Plugin Name: Custom email
Plugin URI: http://www.osclass.org/
Description: -
Version: 0.1
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: myemail
*/
function myemail_form() {
include_once 'form.php';
}
function myemail_before_register() {
$email = Params::getParam('s_email');
if(!preg_match("|^[[:alnum:]]([-_.]?[[:alnum:]])+_?@([[:alnum:]]*\.)?universityname\.ac\.uk$|",$email, $m )) {
osc_add_flash_error_message( __('Your email is not valid', 'myemail')) ;
header('Location: ' . osc_register_account_url());
exit;
}
}
/**
* ADD HOOKS
*/
osc_register_plugin(osc_plugin_path(__FILE__), '');
osc_add_hook(osc_plugin_path(__FILE__)."_uninstall", '');
// run at registration form
osc_add_hook('user_register_form', 'myemail_form');
osc_add_hook('before_user_register', 'myemail_before_register');
?>Also, create a file called, "form.php" and write something "similar" to this (I'm not sure about this part) This code is using JQuery validation plugin (
http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ) You HAVE TO find a proper code to validate only emails from the domain.
<script>
$(document).ready(function(){
$("#s_email").rules("add", {required: true, messages: { required: "<?php _e('Email not valid', 'myemail'); ?>" }});
});
</script>
EXPLANATION:
We're gonna create a plugin (myemail). The plugin will add a PHP rule (I changed from ereg which is deprecated to preg_match, which is also faster function
http://php.net/manual/es/function.ereg.php , but the syntax is almost the same). That check is ok, but that will happen only AFTER the form is submitted. We want to prevent also that happening and display a JS error BEFORE (form.php file) since we're already using jquery validation plugin, best way is to add a new rule to "s_email" field. You should modify that rule to perform the check you want to. I'm not sure if this will work of not, since we already had added rules to that field before, anyway, test it.
Of course, it will be easier to just add the regexp on the core, but, with a plugin you could safely update OSClass when needed.
Thanks