closed New Custom Account Tab

PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
PROBLEM: I am using the form designer to create custom ($profile_???) fields. Now I have too many, so the [Profile] form is getting congested and losing its user-friendliness.

QUESTION: I have created a custom module with a schema.php & includes.php. I am now looking through the OneAll module and Tweaks module (index.php) for clues on how to create the actual account form page. If I wanted just a blank page that included the [form designer] what code do I need to add to my custom module's index.php?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 06/12/19 10:32:43PM
michael
@michael
5 years ago
7,744 posts
If you want the output on the users profile, then not index.php, use profile.php. Very similar to index.php except the views come out on the users profile.

Take a look at one of the modules that has a profile.php file, maybe jrDocs perhaps. in it you will see a function:
profile_view_jrDocs_default()

Which will show at:
yoursite.com/(users profile url)/docs

for that user.
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
I need a page that appears in the "Account Settings" area. Like [profile],[account],[networks]. I looked for some documentation on this subject, but I did not find it. I can see in the Tweaks module that I need a view function that has a
jrUser_account_tabs('myModuleName', $_profile);

So I am sure that I am looking at the correct code section. I was hoping there was a "getting started" document for creating this type of page for a custom module. Again, all I need is a blank page with a [form designer] button.

Thanks!!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
So far I have an empty tab

jrCore_register_module_feature('jrUser', 'account_tab', 'myCustomModule', 'custom', 1);

And I have an empty page in the profile account area:

function view_myCustomModule_custom($_post, $_user, $_conf)
{ global $_mods; jrUser_session_require_login(); jrUser_check_quota_access('myCustomModule'); if (!isset($_post['profile_id']) || !jrCore_checktype($_post['profile_id'], 'number_nz') || !jrProfile_is_profile_owner($_post['profile_id'])) { $_post['profile_id'] = jrUser_get_profile_home_key('_profile_id'); } $_profile = jrUser_get_requested_user_account_info(); if (!$_profile || !is_array($_profile)) { jrCore_notice_page('error', 41); } jrUser_account_tabs('custom', $_profile); $button = null; if (!empty($_profile['profile_name'])) { $button = jrCore_page_button('account-tabs-profile-button', "@{$_profile['profile_url']}", "jrCore_window_location('{$_conf['jrCore_base_url']}/{$_profile['profile_url']}')"); } $_ln = jrUser_load_lang_strings(); jrCore_page_banner(2, $button); jrCore_get_form_notice(); // Form init $_tmp = array( 'submit_value' => 3, 'cancel' => jrCore_is_profile_referrer(), 'form_ajax_submit' => false, 'values' => $_profile ); jrCore_form_create($_tmp); // Profile ID $_tmp = array( 'name' => 'pid', 'type' => 'hidden', 'value' => intval($_profile['_profile_id']) ); jrCore_form_field_create($_tmp); jrCore_page_display(); }

How do I get my tab title to appear?

And how do I make the [form designer] available? (I already have the datastore set up in the schema.php)

Thanks for any help on this :)


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 02/24/19 07:42:34PM
michael
@michael
5 years ago
7,744 posts
This code that you have in your _init() should be making the title appear:
jrCore_register_module_feature('jrUser', 'account_tab', 'myCustomModule', 'custom', 1);
What is the language string for 1? that should be the title. Maybe hard code it
jrCore_register_module_feature('jrUser', 'account_tab', 'myCustomModule', 'custom', "your title");
michael
@michael
5 years ago
7,744 posts
This is how the jrAudio module registers with the form designer in its _init() funtion in include.php

    // Allow admin to customize our forms
    jrCore_register_module_feature('jrCore', 'designer_form', 'jrAudio', 'create');
    jrCore_register_module_feature('jrCore', 'designer_form', 'jrAudio', 'update');
    jrCore_register_module_feature('jrCore', 'designer_form', 'jrAudio', 'create_album');
    jrCore_register_module_feature('jrCore', 'designer_form', 'jrAudio', 'update_album');
The last parameter is the name of the form, the same as the URL its on, so for you that looks like 'custom'.

Maybe if you have the $_profile_id you can store your info in your datastore on that, then look up to see if it exists when the form is visited.
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Thank you :) I am a couple steps closer.
#1. I can see my Tab Title. :)

#2. In looking at jrProfile I added something similar to your suggestion to my include.php:
// Allow admin to customize our forms
    jrCore_register_module_feature('jrCore', 'designer_form', 'myCustomModule', 'create');
    jrCore_register_module_feature('jrCore', 'designer_form', 'myCustomModule', 'settings');
Unfortunately, the Form Designer button is still not showing.

#3. I successfully added a textarea box to my form, but the data is not populating in the datastore:
function view_myCustomModule_custom($_post, $_user, $_conf)
{ ... // Some Info $_tmp = array( 'name' => 'custom_info', 'label' => 4, 'help' => 5, 'type' => 'textarea', 'validate' => 'printable', 'required' => false ); jrCore_form_field_create($_tmp); ... jrCore_page_display(); }

I think the error is in my save function, which I don't understand yet fully.

function view_myCustomModule_custom_save($_post, $_user, $_conf)
{ // Must be logged in jrUser_session_require_login(); jrCore_form_validate($_post); jrUser_check_quota_access('myCustomModule'); // get info about this profile $_pr = jrCore_db_get_item('jrProfile', $pid); $_data = array(); jrCore_form_delete_session(); jrProfile_reset_cache($pid); jrUser_reset_cache($_user['_user_id']); jrCore_set_form_notice('success', 13); jrCore_form_result(); }

When I add data and click submit, I receive the success message, but the datastore is empty.


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
SteveX
SteveX
@ultrajam
5 years ago
2,584 posts
$pid is empty, so you don't get any profile info, but that doesn't matter because you don't do anything with it anyway.

You set $_data to be an empty array, but that doesn't matter because you don't do anything with it either.

You don't save anything (which is why the datastore is empty, although it would still be empty if you did save as your $_data array is set to be empty).

Then you set the form notice to notify you of success, which is why you see the success message.

So you didn't do anything apart from setting a success message, which is why you see that.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Thanks Steve! @ultrajam

Looking closer I think I need to first fill a variable with the form data

$_data = jrCore_form_get_save_data('myCustomModule', 'custom', $_post);

But since I want this module's data to be treated like an array of "settings" that will only be allowed once per profile, I am not sure how (or if I need to) assign the $pid to the data being saved.

Any help is much appreciated. THANKS!!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Good morning! :)

So I am attempting to implement the syntax found here: https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1023/datastores

So far on my Account Settings Page View I have the tab with proper link working (from includes.php), I have a profile id button and I can see the form designer button :) I also have one text area available.

PROBLEM: I am saving an empty set to the datastore (no data at all, that I can see).

//------------------------------
// settings
//------------------------------
function view_myCustomModule_settings($_post, $_user, $_conf)
{ global $_mods; jrUser_session_require_login(); jrUser_check_quota_access('myCustomModule'); if (!isset($_post['profile_id']) || !jrCore_checktype($_post['profile_id'], 'number_nz') || !jrProfile_is_profile_owner($_post['profile_id'])) { $_post['profile_id'] = jrUser_get_profile_home_key('_profile_id'); } $_profile = jrUser_get_requested_user_account_info(); if (!$_profile || !is_array($_profile)) { jrCore_notice_page('error', 41); } jrUser_account_tabs('custom', $_profile); $button = null; if (!empty($_profile['profile_name'])) { $button = jrCore_page_button('account-tabs-profile-button', "@{$_profile['profile_url']}", "jrCore_window_location('{$_conf['jrCore_base_url']}/{$_profile['profile_url']}')"); } $_ln = jrUser_load_lang_strings(); jrCore_page_banner(2, $button); jrCore_get_form_notice(); // Form init $_tmp = array( 'submit_value' => 3, 'cancel' => jrCore_is_profile_referrer(), 'form_ajax_submit' => false, 'values' => $_profile ); jrCore_form_create($_tmp); // If we modifying FROM the Profile Browser, we redirect there on save... $ref = jrCore_get_local_referrer(); if (jrUser_is_admin() && strpos($ref, '/browser')) { $_tmp = array( 'name' => 'from_browser', 'type' => 'hidden', 'value' => $ref ); jrCore_form_field_create($_tmp); } if ((jrUser_is_admin() || jrUser_is_power_user() || jrUser_is_multi_user()) && isset($_post['profile_id']) && jrCore_checktype($_post['profile_id'], 'number_nz')) { $_tmp = array( 'name' => 'profile_id', 'type' => 'hidden', 'value' => $_post['profile_id'] ); jrCore_form_field_create($_tmp); } // Meta Description $_tmp = array( 'name' => 'seo_metadesc', 'label' => 4, 'help' => 5, 'type' => 'textarea', 'validate' => 'printable', 'required' => false ); jrCore_form_field_create($_tmp); jrCore_page_display(); } //------------------------------ // settings_save //------------------------------ function view_myCustomModule_settings_save($_post, $_user, $_conf)
{ // Must be logged in jrUser_session_require_login(); jrCore_form_validate($_post); jrUser_check_quota_access('myCustomModule'); $_data = jrCore_form_get_save_data('myCustomModule', 'settings', $_post); $id = jrCore_db_create_item('myCustomModule', $_data); $_temp = jrCore_db_get_item('myCustomModule', $id); $_more = array(); jrCore_db_update_item('myCustomModule', $id, $_more); jrCore_form_delete_session(); jrUser_reset_cache($_user['_user_id']); jrCore_set_form_notice('success', 6); jrCore_form_result(); }

Could someone please help me out with what I am missing? THANKS!!! :)


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
SteveX
SteveX
@ultrajam
5 years ago
2,584 posts
Use fdebug to write variables to the log.
fdebug($_post);
    $_data = jrCore_form_get_save_data('myCustomModule', 'settings', $_post);
fdebug($_data);



--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
I checked that and all the data from the form shows in the debug log.

But I still cannot get the data to post to the datastore. Plus, I need to make sure there is only one entry per profile_id.

function view_myCustomModule_settings_save($_post, $_user, $_conf)
{ // Must be logged in jrUser_session_require_login(); jrCore_form_validate($_post); jrUser_check_quota_access('myCustomModule'); $_data = jrCore_form_get_save_data('myCustomModule', 'settings', $_post); jrCore_db_update_item('myCustomModule', $_data); jrCore_form_delete_session(); jrUser_reset_cache($_user['_user_id']); jrCore_set_form_notice('success', 6); jrCore_form_result(); }

Thanks!!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
SteveX
SteveX
@ultrajam
5 years ago
2,584 posts
So this is the function
/**
 * Updates an Item in a module datastore
 * @param string $module Module the DataStore belongs to
 * @param int $id Unique ID to update
 * @param array $_data Array of Key => Value pairs for insertion
 * @param array $_core Array of Key => Value pairs for insertion - skips jrCore_db_get_allowed_item_keys()
 * @return bool true on success, false on error
 */
function jrCore_db_update_item($module, $id, $_data = null, $_core = null){
    $func = jrCore_get_active_datastore_function($module, 'db_update_item');
    return $func($module, $id, $_data, $_core);
}
So it needs to be passed the parameters in this order - the module name (which you have), then the item id, then the data array.

You pass in the data array instead of the item id. Do you have the item_id in your fdebug? If so, try jrCore_db_update_item('myCustomModule', $_data['item_id'], $_data);


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
This is the data that my form currently creates:
Array ( 
[_uri] => /custom/settings_save
[jr_html_form_token] => 13a96ce33f4ae8d9b265203bf9a7ea4f
[jr_html_form_profile_id] => 1
[profile_id] => 1
[seo_metadesc] => hello you
[module_url] => custom
[module] => myCustomModule
[option] => settings_save
 )

I tried using 'profile_id', but it did not work:
function view_myCustomModule_settings_save($_post, $_user, $_conf)
{ // Must be logged in jrUser_session_require_login(); jrCore_form_validate($_post); jrUser_check_quota_access('myCustomModule'); $_data = jrCore_form_get_save_data('myCustomModule', 'settings', $_post); jrCore_db_update_item('myCustomModule', $_data['profile_id'], $_data); jrCore_form_delete_session(); jrUser_reset_cache($_user['_user_id']); jrCore_set_form_notice('success', 6); jrCore_form_result(); }

Any other data point I could use?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
michael
@michael
5 years ago
7,744 posts
if you put
fdebug($_data)
and you got that array that includes 'profile_id' then to use that you use
$_data['profile_id']

I like this structure for fdebug()
$_debug = array(
'WHAT' => 'Im trying to figure out what i have in this location',
'$_data' => $_data,
);
fdebug($_debug);

So instead of just some variables, I also get a message that I set so I know why I wanted it.
michael
@michael
5 years ago
7,744 posts
Also if you're trying to use the jrCore_db_update_item() function then make sure you're only doing so AFTER you've used the jrCore_db_create_item() function.

And only pass in arrays that begin with the name of the datastore. ie
'profile_????'

if you're trying to put it into the profile datastore.
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
@michael Thank you. I tried your debug code and noticed that the $_post data is NOT passing into the $_data variable.
So this is not working:
$_data = jrCore_form_get_save_data('myCustomModule', 'settings', $_post);

What should I do next?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 03/13/19 06:36:35PM
michael
@michael
5 years ago
7,744 posts
The docblock for jrCore_form_get_saved_data() reads:
Get all posted data that can be saved to the Data Store for a module
 * @param string $module Module that has registered a designer form view
 * @param string $view View to get form fields for
 * @param array $_data $_REQUEST data to parse (default is $_post)
 * @return mixed
 */

It takes $_post and cleans out everything that is not going to be able to be stored in your modules datastore.

So that means everything that does not have the prefix of your modules datastore.

so you need to check the names of your form field line up with what is going into your datastore.

eg: if in your modules schema.php file you have:
    jrCore_db_create_datastore('myCustomModule', 'report');

then your form fields in your 'settings' form would need to look like this:
    // report_id
    $_tmp = array(
        'name'  => 'report_id',
        'type'  => 'hidden',
        'value' => $_report['_item_id']
    );
    jrCore_form_field_create($_tmp);


    // Report body
    $_tmp = array(
        'name'     => 'report_body',
        'label'    => 'Report',
        'help'     => 'Enter any report body into this area',
        'type'     => 'textarea',
        'validate' => 'printable',
        'required' => true
    );
    jrCore_form_field_create($_tmp);
.....

The 'name' lines up with what datastore value the input value will be stored on.
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
@michael Thank you!

When I perform the debug I am not getting any data to populate for this:

// custom_id
    $_tmp = array(
        'name'  => 'custom_id',
        'type'  => 'hidden',
        'value' => $_custom['_item_id']
    );
    jrCore_form_field_create($_tmp);

I am seeing the $_data for this textarea field when I enter data (so I am doing something right):

// Custom Description
    $_tmp = array(
        'name'     => 'custom_desc',
        'label'    => 4,
        'help'     => 5,
        'type'     => 'textarea',
        'validate' => 'printable',
        'required' => false
    );
    jrCore_form_field_create($_tmp);

What do I need to do to ensure that an _item_id is generated?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 03/14/19 08:44:42AM
brian
@brian
5 years ago
10,148 posts
Did you confirm that "custom" is set as your datastore prefix in your schema.php file?

The item_id is created (and returned) when you make the call to jrCore_db_create_item() in your action view.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
So here is what I have currently (I am using "custom" for the sake of the forum, but I have verified that my schema is working):

Here is my view form function, which does show me one textarea and the [Form Designer] button. In this example I open the Form and entered "New Attempt" in the Textarea and clicked save. I then received a success message; however, an empty entry was made into the datastore.

function view_myCustomModule_settings($_post, $_user, $_conf)
{ global $_mods; jrUser_session_require_login(); jrUser_check_quota_access('myCustomModule'); if (!isset($_post['profile_id']) || !jrCore_checktype($_post['profile_id'], 'number_nz') || !jrProfile_is_profile_owner($_post['profile_id'])) { $_post['profile_id'] = jrUser_get_profile_home_key('_profile_id'); } $_profile = jrUser_get_requested_user_account_info(); if (!$_profile || !is_array($_profile)) { jrCore_notice_page('error', 41); } jrUser_account_tabs('custom', $_profile); $button = null; if (!empty($_profile['profile_name'])) { $button = jrCore_page_button('account-tabs-profile-button', "@{$_profile['profile_url']}", "jrCore_window_location('{$_conf['jrCore_base_url']}/{$_profile['profile_url']}')"); } $_ln = jrUser_load_lang_strings(); jrCore_page_banner(2, $button); jrCore_get_form_notice(); // Form init $_tmp = array( 'submit_value' => 3, 'cancel' => jrCore_is_profile_referrer(), 'form_ajax_submit' => false, 'values' => $_profile ); jrCore_form_create($_tmp); // Profile ID $_tmp = array( 'name' => 'pid', 'type' => 'hidden', 'value' => intval($_profile['_profile_id']) ); jrCore_form_field_create($_tmp); if ((jrUser_is_admin() || jrUser_is_power_user() || jrUser_is_multi_user()) && isset($_post['profile_id']) && jrCore_checktype($_post['profile_id'], 'number_nz')) { $_tmp = array( 'name' => 'profile_id', 'type' => 'hidden', 'value' => $_post['profile_id'] ); jrCore_form_field_create($_tmp); } // custom_id $_tmp = array( 'name' => 'custom_id', 'type' => 'hidden', 'value' => $_custom['_item_id'] ); jrCore_form_field_create($_tmp); // Custom Description $_tmp = array( 'name' => 'custom_desc', 'label' => 4, 'help' => 5, 'type' => 'textarea', 'validate' => 'printable', 'required' => false ); jrCore_form_field_create($_tmp); jrCore_page_display(); }

This form is generating data for $_post
[$_post] => Array (
[_uri] => /custom/settings_save
[jr_html_form_token] => 4a2a85f2898ad82ee143df4c35a055c5
[jr_html_form_profile_id] => 1 
[pid] => 1 
[profile_id] => 1 
[custom_id] => 
[custom_desc] => New Attempt 
[module_url] => custom 
[module] => myCustomModule 
[option] => settings_save
 )

Next, I set up a save view function. This is where I am getting hung up, but I am sure I also have an issue in the form above since I can't get the _item_id to populate.
function view_MyCustomModule_settings_save($_post, $_user, $_conf)
{ // Must be logged in jrUser_session_require_login(); jrCore_form_validate($_post); jrUser_check_quota_access('MyCustomModule'); $_data = jrCore_form_get_save_data('MyCustomModule', 'settings', $_post); //remove debug after tests $_debug = array( 'WHAT' => 'Im trying to figure out what I have in this location', '$_data' => $_data, '$_post' => $_post, ); fdebug($_debug); jrCore_db_create_item('MyCustomModule', $_data['profile_id'], $_data); jrCore_form_delete_session(); jrUser_reset_cache($_user['_user_id']); jrCore_set_form_notice('success', 6); jrCore_form_result(); }

The debug is also telling me that my $_data is populating, although the _item_index is empty.
[$_data] => Array (
[custom_id] => 
[custom_desc] => New Attempt 
)

I hope this helps to clarify my dilema. Thanks!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
brian
@brian
5 years ago
10,148 posts
$_custom is not set:

// custom_id
    $_tmp = array(
        'name'  => 'custom_id',
        'type'  => 'hidden',
        'value' => $_custom['_item_id']
    );
    jrCore_form_field_create($_tmp);

That will be empty. I'm not even sure what you are trying to do with that.

Note - if you want our team to build this for you open a ticket - this is beyond what we can assist with in the forum.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags