Skip to content

Custom fields won't save to the account form. #864

@johnkawakami

Description

@johnkawakami

When I make a custom field, it won't save to the form.

It can be fixed by going into the database, into the uwp_form_fields and setting the 'form_type' field to 'account'.

It appears that the problem is that the form_type value is being lost somewhere. The process of creating the form field requires the form_type=account to be passed around, from the server to the client, then back to the server.

I'm not sure if this is the problem line. I'm still working this out, tracing the process.

$this->form_field_adminhtml( $field_type, $result_str, $field_ins_upd, $field_type_key );


I wrote some code to make a Custom Field. Here's the code. It's just a copy of the Twitter custom field, but altered slightly to create a BlueSky field.

add_action( 'init', function() {
	add_filter( 'uwp_form_fields_custom', 'custom_form_fields_custom', 10, 1 );
});

function custom_form_fields_custom( $custom_fields ) {
$custom_fields['bluesky'] = array(
	'field_type' => 'url',
	'class'      => 'uwp-twitter',
	'field_icon' => 'fab fa-twitter-square',
	'site_title' => __( 'BlueSky', 'userswp' ),
	'help_text'  => __( 'Let users enter their bluesky url.', 'userswp' ),
	'defaults'   => array(
		'admin_title'   => 'BlueSky',
		'site_title'    => 'BlueSky',
		'form_label'    => __( 'BlueSky url', 'userswp' ),
		'htmlvar_name'  => 'bluesky',
		'is_active'     => 1,
		'default_value' => '',
		'is_required'   => 0,
		'required_msg'  => '',
		'field_icon'    => 'fab fa-twitter',
		'css_class'     => 'btn-twitter',
	)
);
}

That works correctly to display a new custom field in the "custom field" section of the form builder at wp-admin/admin.php?page=uwp_form_builder.

The value of form_type from the server side appears to be exposed via some HTML that's generated, and is wrapped in a <script type="text/template"></script> code block.

On the client side, it extracts this value, and uses it to produce a GET request to the admin-ajax.php service like this:

https://example.com/wp-admin/admin-ajax.php?action=uwp_ajax_action&create_field=true&htmlvar_name=friendster&field_type=url&field_type_key=friendster&field_id=new281&field_ins_upd=new&manage_field_type=custom_fields&custom_type=custom&form_id=1

The selector for the element is #form-type, and there are 6 instances on the page. 5 of them have a value of "account", and one, BlueSky custom field, has a value of "".

This line jumped out at me because it's not passing $form_type to the method.

$this->form_field_adminhtml( $field_type, $result_str, $field_ins_upd, $field_type_key );

Further down, this code generates the HTML for the custom field.

public function admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false ) {

It should set the form-type to 'account', but, because it's not passed, it's set to the default value of null.

I'm going to keep working on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions