Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Is it possible to make a databound form that displays all pages in a certain folder in a dropdown, where the user can pick from and when he fills out the form, there isn't created a new cloned page, but adds to that existing selected cloned page's repeatable region?

Especially the adding to repeatable regions instead of creating a new cloned page is what bothers me the most, I guess I can figure out the rest myself.

This aside:
Why would I want to do it like this? Let me give you some more context. I would like to have an "Events" masterpage where the folders are "the events" and the cloned page represents an activity of that event. Inside there are repeatable regions with the subscriptions for that event's activity. So I could make a page event/foldername that would display a form where a user can pick an activity, fill in other details and submit. What is important is that the order of the subscriptions could be easily altered afterwards, that's why I think the repeatable regions would be the most interesting.

I also would like some fields that shouldn't be filled in on the front-end, only the back-end. We would like to receive the payment at the event itself, so we (admins at the entrance) would be able to keep track of payments, of course this shouldn't be filled in by the customer themselves. Is it possible to ignore fields in a databound form, or should I use something like a hidden field with a default value in the form?

By the way: I'm not asking for someone else to write the entire code, but I just would like to know if my idea would be possible so I could lay out the base structure before running in to much trouble.
davestephans wrote: Is it possible to make a databound form that displays all pages in a certain folder in a dropdown, where the user can pick from and when he fills out the form, there isn't created a new cloned page


Hi, here is a solution for the quoted part.

1. Let's create a simple Couch-managed form, which lists all pages in a dropdown
Code: Select all
<cms:capture into='my_pages' trim='1'>
    <cms:pages masterpage=k_template_name skip_custom_fields='1' show_future_entries='1' >
        <cms:show k_page_title /> = <cms:show k_page_id />
        <cms:if "<cms:not k_paginated_bottom />">|</cms:if>
    </cms:pages>
</cms:capture>

<cms:set my_values = "<cms:concat 'Please select =- | ' my_pages />" scope='global' />
<cms:form method="post" anchor='0'>
    <cms:input type='dropdown' opt_values=my_values name='page_edited' label='Page to edit' required='1' />
    <button type="submit">Submit</button>
    <cms:if k_success>
        <cms:dump />
        <p><a href="<cms:show k_template_link />">reload</a></p>
    </cms:if>
    <cms:if k_error><p><kbd><cms:show k_error /></kbd></p></cms:if>
</cms:form>



Running the code above and submitting the form would show the id of requested page in dump (frm_page_edited):
2017-10-25-124708.png
2017-10-25-124708.png (8.13 KiB) Viewed 80 times


Now we know the user selected page and we can use the 'db_persist' tag. I modified the 'k_success' block of the form. Also I added an editable to the template to store some text there.
Code: Select all
<cms:editable type='text' name='text' label='text' />



Code: Select all
<h2>Pages:</h2>
<ul>
    <cms:pages show_future_entries='1' skip_custom_fields='0' show_unpublished='0' >
        <li>
            <a href="<cms:show k_page_link />">
                <cms:show k_page_title /></a> (<a href="<cms:admin_link />">admin link</a>)<cms:if text> : <cms:show text /></cms:if>

        </li>
        <cms:no_results>
            <cms:abort >Please add some pages first (in backend)..</cms:abort>
        </cms:no_results>
    </cms:pages>
</ul>

<cms:capture into='my_pages' trim='1'>
    <cms:pages masterpage=k_template_name skip_custom_fields='1' show_future_entries='1' >
        <cms:show k_page_title /> = <cms:show k_page_id />
        <cms:if "<cms:not k_paginated_bottom />">|</cms:if>
    </cms:pages>
</cms:capture>

<cms:set my_values = "<cms:concat 'Please select =- | ' my_pages />" scope='global' />
<cms:form method="post" anchor='0'>
    <cms:input type='dropdown' opt_values=my_values name='page_edited' label='Page to edit' required='1' />
    <button type="submit">Edit</button>
    <cms:if k_success>
        <cms:db_persist _mode='edit' _masterpage=k_template_name _page_id = frm_page_edited text="page <i><cms:get_field 'k_page_title' masterpage=k_template_name id=frm_page_edited /></i> has been edited OK!" />
        <cms:redirect k_template_link />
    </cms:if>
    <cms:if k_error><p><kbd><cms:show k_error /></kbd></p></cms:if>
</cms:form>



I have 5 samples pages in backend. The result of submitted form and above code is like this:
2017-10-25-130418.png
2017-10-25-130418.png (7.53 KiB) Viewed 80 times



Now it is a minimal barebone working sample, that hopefully can get you started.
2 posts Page 1 of 1

Who is online

In total there are 4 users online :: 1 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Bing [Bot] and 3 guests