Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hello Couch Admin,
I want to know if it is possible to use dynamic folders values to show or hide editable fields just like we use dropdown or radio editable fields to show or hide other editable fields using conditional functions? Thanks
Hi,

Is this what you are looking for ? -
viewtopic.php?f=5&t=11512#p30878
Thank you KK,
I had a look at the link you sent. However in my case I want the dynamic dropdown to be just the plain text of the folder titles so I did this in my dynamic_params.html file in the snippets folder:
Code: Select all
<!-- dynamic_params.htm in snippet -->
Please select=-|
<cms:folders childof='' hierarchical='1' depth='0' orderby='weight' order='asc'>
    <cms:set pad = "<cms:repeat k_level>- &nbsp;&nbsp;&nbsp;</cms:repeat>" />
    <cms:show pad /><cms:show k_folder_title /> |
</cms:folders>

<!-- Template with dropdown field which will yield the following "Please select=- | Folder title 1 | Folder title 2 | Folder title 3 " -->
<cms:editable name="test_field"
   label="First sensei"
   opt_values='properties_dynamic_params.htm'
   dynamic='opt_values'
   type='dropdown'
   order='-2'
/>


To be able to use the test_field to set the system folder I have to find a way to use the value from the test_field to get the id of the folder so I tried to use <cms:php>...</cms:php> in the templates config_form_form view but it is not working.

The reason I am going this path is because I had created the template a long time and have about 72 conditional functions and sub-conditional functions in the template so if I should use the dropdown like this "Please select=- | Folder 1 title = folder_1_name | Folder 2 title = folder_2_name | Folder 3 title = folder_3_name ", it will mean I have to go through each conditional function and sub conditional functions and change all the values of the function parameters to match the folder name instead of the space separated folder titles I initially used. I hope you get me?

In my solution I tried doing this but it didn't work
Code: Select all
<cms:config_form_view>
<cms:php>
    global $CTX;
    $property_status_sel="<cms:show frm_test_field />";
    $property_status_sel = str_replace([' ', '/'], '-', strtolower($property_status_sel));

    $CTX->set('property_status_sel',$property_status_sel,'global');
</cms:php>
<cms:persist
    k_page_folder_id = "<cms:if property_status_sel ne '-' >
       <cms:folders root=property_status_sel depth='1'><cms:show k_folder_id /></cms:folders>
    <cms:else />
        -1
    </cms:if>"
    />

</cms:config_form_view>
The PHP routine converting 'title' to 'name' needs to be executed from within the <cms:persist> block while setting the 'k_page_folder_id' parameter.

However, since everything now would require to be enclosed within double-quotes, chances of making a syntax error in the PHP code would be imminent. To prevent that, please place the PHP code in your kfunctions.php file as an ordinary function e.g. as follows -
Code: Select all
function my_set_property_status(){
    global $CTX, $FUNCS;

    $property_status_sel = $CTX->get( 'frm_test_field' );
    $property_status_sel = $FUNCS->get_clean_url( $property_status_sel );

    $CTX->set( 'property_status_sel', $property_status_sel, 'global' );
}

.. and then call that function from within <cms:persist> as follows -
Code: Select all
<cms:persist
    k_page_folder_id = "
        <cms:php>
            my_set_property_status();
        </cms:php>

        <cms:if property_status_sel ne '-' >
           <cms:folders root=property_status_sel depth='1'><cms:show k_folder_id /></cms:folders>
        <cms:else />
            -1
        </cms:if>
    "   
/>

Hope this helps.
Hello Admin,
Yes it did help. Thanks for your assistance.
As a follow up question, I guess I have a lot to learn in Couch.
I have a few editable fields with required parameters set to 1. I show or hide these fields using the conditional function I asked you about.
Now I am trying to create a review system so that when a use is viewing a page they will be able to add reviews with the stars voting addon ( I am giving the votes addon a try). So I did this for the review form:

Code: Select all
<cms:form masterpage=k_template_name mode='edit' page_id=k_page_id anchor='0' method='post'>

<cms:if k_success>
<cms:db_persist_form page_rating=frm_stars />

<cms:if k_success>
            <cms:db_persist
            _masterpage='reviews.php'
            _mode='create'
            method='post'
            anchor='0'
            _invalidate_cache='0'
            _auto_title='0'

            k_page_title=current_user
            k_page_name="<cms:random_name />"

            reviewer_email=current_user_email
            page_review=frm_stars
            review_owner=k_user_id
            page_reviewed="<cms:show k_page_id />"
            review_msg=frm_review_msg

            />

</cms:if>

........
</cms:if>


However I keep getting this error: Required field cannot be left empty. Meanwhile for that particular page the fields showing the error are hidden and its even correct at the backend so I am confused as to why I am getting those errors. The errors are showing for all the required fields that are hidden for the page in view.

If I view another page and try to submit a review, it then shows errors for required fields are supposed to be activated r are suposed to show only if certain conditions are met when using the conditional functions ate the backend.
I think following could be the issue -
the <cms:db_persist_form> tag, as opposed to <cms:db_persist>, expects all the 'controlling' fields (i.e. on which the conditional fields are dependent) to be actually present in the form.

Please check and chances are that the fields being mentioned in the error messages are not a part of your form.

Perhaps my response in the following thread would help you in sorting this -
viewtopic.php?f=4&t=12551

Hope this helps.
Ok Admin,
Thank you very much. It worked.
8 posts Page 1 of 1
cron