Adding a registration field and custom validation via plugin

Hello guys!

 Im new to Elgg but have been doing web development with php/js/html/css for 7+ years. Im trying to make a plugin that in user registration asks for the users zip code and after checking if it is one of our valid zip codes it allows them to register; otherwise it denies them access. 

Ive looked through some existing plugins that add fields trying to get the basics of changing the registration page but to no avail. I have a copied the vendor actions/register.php and views/forms/register.php and added an input in both places but do not understand the start.php registration of a custom register page. I tried reading the docs on this and it was hard to grasp. Maybe I just need to take a break for a bit but any help would be much appreciated! 

  • but do not understand the start.php registration of a custom register page

    elgg_unregister_page_handler('register', 'elgg_user_account_page_handler');
    
    elgg_register_page_handler('register', 'custom_user_account_page_handler');

    Look at elgg_user_account_page_handler() to override it with your custom function.

    Also, you can try Profile manager plugin which included the validation and custom forms already (use latest release on GitHub).

  • @RvR Thanks for the response! 

    That makes sense - the only thing im missing now is how to call the view I have in my plugins views/default/forms/register.php instead of "echo elgg_view_resource("account/register");" I don't see how account/register is pointing to their views/default/forms/register. 

    If Im missing some overarching concept apologies, but Im new! 

  • Also I was originally looking into Profile Manager - maybe ill give it another try but it didn't seem to allow me to make custom validation. 

  • elgg_view_resource() grabs the view from "resources/<resrouce>", that in turns calls elgg_view_form(), which grabs the view from "forms/<form>". 

    You can extend the register form using elgg_extend_view(). If you are overriding the view in your plugin, make sure to flush the system cache.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking