Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hello All, @KK Sir, @trendoman,

I am trying to same the id/name/title of a relation field as the k_page_title of a DBF with _auto_title='0'.
Is there a straight forward method for the same that I am missing out?

Here is a small sample code to make the picture clear!

Code: Select all
<?php require_once('../couch/cms.php'); ?>
<cms:template title="Save Relation Id" clonable="1">
   <cms:editable name="rel_district" label="District Relation" type="relation" has="one" masterpage="district/names.php" required="1" order="1" />
   <cms:editable name="text" label="Text" type="text" required="1" order="2" />
</cms:template>
   <cms:set submit_success="<cms:get_flash 'submit_success' />" />
    <cms:if submit_success >
        <h4>Success: Your application has been submitted.</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'
                k_page_title="<cms:pages masterpage='test/save_relation.php' ><cms:related_pages 'rel_district' page_title='<cms:show frm_rel_district />' limit='1'><cms:show district /></cms:related_pages></cms:pages>_<cms:show frm_text />"
            />
            <cms:if k_success>
               <cms:set_flash name='submit_success' value='1' />
               <cms:redirect k_page_link />
           </cms:if>
        </cms:if>

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

        <label>District</label>
        <cms:input name="rel_district" type="bound" />
        <br />

        <label>Text</label>
        <cms:input name="text" type="bound" />
        <br />

        <button type="submit">Submit Application</button>
    </cms:form>
<?php COUCH::invoke(); ?>


It would be
Code: Select all
k_page_title="<cms:pages masterpage='test/save_relation.php' ><cms:related_pages 'rel_district' page_title='<cms:show frm_rel_district />' limit='1'><cms:show district /></cms:related_pages></cms:pages>"

where the k_page_title is set to id/name/title_text.

For example:
Relational Field has values: Type A, Type B
Text Field can take any user entered value.
so the DBF title should be:
1. Type A_text or Type B_text
or
2. type-a_text or type-b_text
or
3. using id (if Type A has id 1 and Type B has id 2)
1_text or 2_text

Please help!

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
Hi,

In your code, you are trying to fetch data of a page that has been 'related' to the page being saved through a bound dropdown.
Problem is that at the point you are doing this, the page has *not* yet been saved! So, <cms:related_pages> will get back nothing.

There are alternatives and I discussed those with Aashish on a similar issue before.
The one that worked for him was this -
viewtopic.php?f=4&t=12768#p36120

Please try using that.

Hope this helps.
@KK Sir,

I have tried that method which you have pointed to. But the issue is that when I edit a page (CRUD) from the frontend, the relational dropdown value is displayed but not saved.

Is there no straight forward method to save the relational field as we have for the text fields? like:
Code: Select all
<cms:show frm_text />


Regards,
GenXCoders (Priya)
Image
where innovation meets technology
Is there no straight forward method to save the relational field as we have for the text fields? like:
<cms:show frm_text />

Regrettably, there indeed was not.
But I have now tried to fix that by pushing a new commit to GitHub.

Please get the revised version of Couch (or maybe just the 'couch/addons/relation/relation.php' file) from GitHub and now you'll find that
<cms:show frm_rel_district /> will output the 'id' of all pages selected in it.

You can use that id to get full data from the related page e.g. in your case -
Code: Select all
<cms:db_persist_form
    _invalidate_cache='0'
    _auto_title='0'
    k_page_title="<cms:pages masterpage='district/names.php' id=frm_rel_district limit='1'><cms:show district /></cms:pages>_<cms:show frm_text />"
/>

Hope this helps. Do let me know.
Thats sweet sir.
I will try it out and revert back.

Regards!

EDIT1:
Sir this works as expected. Thanks a lot.
Image
where innovation meets technology
5 posts Page 1 of 1
cron