Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Saving custom registration fields to database

New to Vanilla Forums and plugin development for this platform and I have spent a considerable amount of time trying to find the answer in the forum and in other plugins but not really got anywhere.

I have added a custom field to my registration page 'Real Name' and whilst logged in, I can view it in the profile page and edit my profile, it modifies the value and saves/updates it in the database (manually added column in database table) - that is all working perfectly.

But on the registration page, the form just keeps returning the error 'RealName is required'.

My questions:-

1) Exactly what code determines whether a field is required or not? I can not see what sets this from the below...

echo $this->Form->Label('Real Name', 'RealName'); echo Wrap(sprintf(T('Not visible to other members.')), 'div', array('class' => 'Gloss')); echo $this->Form->TextBox('Real Name', array('autocorrect' => 'off', 'autocapitalize' => 'off', 'Wrap' => TRUE, 'Placeholder' => 'Real Name'));

2) How do I save this field to the database when saving the registration form? I fail to see any other similar scenario or existing example of this.

My modifications exist in a plugin and theme files. Please don't suggest ProfileExtender or some other plugin because they are not what I am looking for and do not resolve the scenario.

Comments

  • Well I have figured out that the 'required' error was being triggered whilst the column for 'RealName' existed in the database table. Dropping the column removed the error.

    I've actually given up on this now, I can't figure this out at all frustratingly...

  • hgtonighthgtonight ∞ · New Moderator

    The requirement is probably based on the schema of the corresponding DB column. Make the column nullable and the required validation function won't get called.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • R_JR_J Ex-Fanboy Munich Admin

    Actually it is quite easy to simply extend a form and I guess you already had all the required steps. Don't know how you have created the column in the database at first, but be sure you make this field nullable if it should not be required.

    Garden (the underlying framework for Vanilla) creates a scheme based on the table and if there is a value required in the database, you will not be able to pass the form without a value.

    You can take a look at this howto to get an impression how many steps you have been away from reaching your goal: http://vanillawiki.homebrewforums.net/index.php/Practical_Example:_How_to_Extend_Existing_Forms

  • peregrineperegrine MVP
    edited November 2015

    aside from r_j's advice on doing yourself.

    Did you give profile extender plugin a try, I thought that was what it was for.

    you could potentially add the field to the user table, or just let profile extender use the user meta table.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • R_JR_J Ex-Fanboy Munich Admin

    @hgtonight: I didn't have seen your post already explaining the requirement. That happens when I forget to refresh the page before answering...

    @peregrine said:
    Did you give profile extender plugin a try, I thought that was what it was for.

    That was also my first thought, but:

    @zigojacko said:
    Please don't suggest ProfileExtender or some other plugin because they are not what I am looking for and do not resolve the scenario.

    ;)

  • @R_J said:
    Actually it is quite easy to simply extend a form and I guess you already had all the required steps. Don't know how you have created the column in the database at first, but be sure you make this field nullable if it should not be required.

    Garden (the underlying framework for Vanilla) creates a scheme based on the table and if there is a value required in the database, you will not be able to pass the form without a value.

    You can take a look at this howto to get an impression how many steps you have been away from reaching your goal: http://vanillawiki.homebrewforums.net/index.php/Practical_Example:_How_to_Extend_Existing_Forms

    Excellent - thank you - that wiki was just what I was after and I am now getting somewhere.

    Shame the wiki was so hidden.

    Thanks again :)

  • Yes, database row just needed to be NULLable - thanks.

    Only reason I don't want to use ProfileExtender is because it is incredibly basic and there is no flexibility on where you want to insert new fields into the registration form or profile page. They all get lumped together at the bottom and don't contain the same markup/styling as the rest of the form.

Sign In or Register to comment.