Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
hi there,
I'm getting back into Couch for a new project, and using the same methods I used before (databound forms and inline editing) to create a website for collaborative translation work. Logged-in users would be allowed to submit text and some metadata, to create pages from a clonable template.

Previously I let the databound form create the cloned page titles using the _auto_title='1' setting. But I'd prefer to set the title based on the content submitted, so that the titles on the back end are more intelligible, instead of purely the random string. Or perhaps the random string could be added to a character-delimited string from the data submitted.

The problem is, I can't seem to create pages without setting the title automatically. I'm testing this by just trying to set the title of the newly created cloned page from an input field, but it fails to create it.

The tutorial here (https://docs.couchcms.com/concepts/databound-forms.html) talks about either hard-coding the page title, or using auto_title='1', but doesn't show how to let the user provide a title (or, as the tutorial says "instead of hard-coding the values you'd want to use some code or algorithm to provide unique values"). When I've tried to add a manually filled out title field to the form, the submitted data ends up not being saved.

If you get a chance would you please look at the code below and point out what I need to change (i.e. I assume specifically inside the db_persist_form tag) to get the desired result, a manually entered title for the new cloned page, or one that uses part of the submitted content plus a random string?
(The code also contains stuff to delete existing fragments, which I took over from my earlier build. Eventually I'd also want to integrate 'edit' features of databound forms but I'm going one step at a time :)

Thanks in advance for any help.


(I'm just using a single editable field atm, but this would be expanded after I get the basics right.)

Code: Select all
<cms:template title='ccc page' clonable='1' dynamic_folders='1'>

<cms:editable name='fragment' required='1' type='textarea'/><!-- fragment text -->
</cms:template>


Code: Select all
<cms:if k_logged_in >
<div id="add_and_delete">
<!-- all for proper form -->

<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
    <h4>New fragment has been stored. (Reload the page to show it.)</h4>
</cms:if>


<cms:form
    masterpage=k_template_name
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

    <cms:if k_success >

        <cms:db_persist_form
            _invalidate_cache='0'
            _auto_title='0'
        />

        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_page_link />
    </cms:if>

    <cms:if k_error >
        <div class="error">
            <cms:each k_error >
                <br><cms:show item />
            </cms:each>
        </div>
    </cms:if>

    <label>Add new fragment:</label>
    <cms:input name="fragment" type="bound" class="paragraph" />
<cms:show k_page_title/>
    <cms:input name="k_page_title" type="bound" />
    <cms:input name="k_page_folder_id" type="bound" />

    <cms:if "<cms:not submit_success />" >
        <button type="submit">+ Add new</button>
    </cms:if>
</cms:form>


<cms:if k_logged_in>
<cms:if k_is_page >

    <cms:set page_to_delete=k_page_id 'global' />

    <cms:form method='post' anchor='0' >
        <!--
            Step 1. Create a string describing the action to create the nonce for.
            Make sure that the string also contains the affected page's id.
            In this example the string would be "delete_page_277" for deleting page with id 277.
        -->
        <cms:set my_action="delete_page_<cms:show page_to_delete />" />
           
        <cms:if k_success>
            <!-- Step 3. Verify the submitted nonce -->
            <cms:validate_nonce my_action />
           
            <!-- If we are here, the nonce was verified and we can execute the action -->
            <!-- Delete the specified page -->
            <cms:db_delete masterpage=k_template_name page_id=page_to_delete />
           
            <!-- redirect to the list-page -->
            <cms:redirect "<cms:link masterpage=k_template_name />" />
           
        </cms:if>   
       
        <!--
            Step 2. Create a nonce for the action (created in step 1 above ).
            This will be submitted with the form.
        -->
        <cms:input name='nonce' type='hidden' value="<cms:create_nonce my_action />" />
       
        <input type="checkbox" required="1" name="confirm_yn" opt_values="y | n" title="select to confirm deletion"/>
        <input type="submit" name="submit" value="Delete this fragment"/>
       
    </cms:form>

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

</div> <!-- closes add_and_delete -->

</cms:if >
Cheers, yes I did but didn't find that topic.
3 posts Page 1 of 1