Jump to content

New type of profile field


Adriano Faria

Recommended Posts

I created a new type of profile field but I can't seem to find how to use my own template as it doesn't has a class on form helper due to that in CustomField model:

	/**
	 * Build Form Helper
	 *
	 * @param	mixed		$value					The value
	 * @param	callback	$customValidationCode	Custom validation code
	 * @return \IPS\Helpers\Form\FormAbstract
	 */
	public function buildHelper( $value=NULL, $customValidationCode=NULL )
	{
		$class = '\IPS\Helpers\Form\\' . $this->type;
		
		/* Hooks can add custom field types which are stored in the database. Toggling the hook can then stop the hook from loading the field class giving a class not found error */
		if ( ! class_exists( $class ) )
		{
			$class = '\IPS\Helpers\Form\\Text';
		}

so it shows like a text box:

lXtyoRG.png

How can I use my own template? Bad approach via hook?

EDIT: As this isn't a markeplace resource, I can easily solve this by uploading my .php file to the form helper directory but I want to see if there's a way.

Link to comment
Share on other sites

4 hours ago, Daniel F said:

Take a look at the custom fields included in commerce 😉 

They're implementing their own custom field class and overriding buildHelper to return the proper class based on the type.

Hi Daniel, thanks for replying. I just took a look and unless I misunderstood, that's not what I need/want. What the above does is to create a new type of custom fields for Packages and Customer. I don't need to create a new type of custom field to a specific area of my app. I need to create a new type of PROFILE field (Core app) so when the user goes to EDIT PROFILE to add/edit it shows the way I want and not with a text box, like my image above.

Link to comment
Share on other sites

If you want to create a new type of profile field, realistically your best option is to create a new form field type, and then add the hook that lets you use this form field type when setting up custom profile fields.

As you're seeing, the form field HTML we output is pretty much directly what the actual form helper class returns. You're going to run into challenges trying to use a built in form helper class, but change the HTML used for the form.

Note that a custom form helper class can extend an existing one, and then you can JUST change the html() method to return your custom form HTML. You don't have to write the entire form helper class from the ground up.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...