Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Hi.

I am trying to filter clonable pages with a custom_field, but it's not working.
Here's my code :

Code: Select all
<cms:pages masterpage="contrat-conferencier.php" custom_field='my_uid=my_uid'>

<cms:form
    masterpage="contrat-conferencier.php"
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

    <cms:input name='submit' type="submit" id="convert" class="btn btn-primary" value="Générer le contrat Conférencier" />

<cms:if k_success>

    <cms:db_persist_form
    _invalidate_cache='0'
    _auto_title='1'
    my_uid=my_uid
    conferencier_dropdown="<cms:related_pages 'conferencier_dropdown' ids_only='1' />"
    langue=langue
    author=author

      />


    <cms:redirect "http://localhost:8888/edit/?o=contrat-conferencier.php&q=list"  />"


</cms:if>

</cms:form>

</cms:pages>


This is in a custom admin theme page.

The "contrat-conferencier.php" page has a text input editable region with the name of "my_uid".
The "contrats.php" page (which is the one where I have put this code in) also has a "my_uid" region, but it's the new addon "sequential ID" region.

What I want to do, is to display a button that allow the user to create a page from another template if the "my_uid" fields matches between these 2 pages.

Is that because the "sequential ID" addon is not working inside the "custom_field" option?
Even so, I tried doing "my_uid=35760", which is an existing page with that text in the "my_uid" text field in the "contrat-conferencier.php", and it's not working either. And the "my_uid" field in that page is not using the addon, it's just a regular text field.

Thanks!
Hi,

Suppose there exists a cloned page of contrat-conferencier.php that has a value of '1234' in its 'my_uid' field, the following code should fetch that page -
Code: Select all
<cms:pages masterpage="contrat-conferencier.php" custom_field='my_uid=1234'>
    <cms:show k_page_name />
</cms:pages>

Please test the code above by placing it in some template and confirm if you can fetch that page.
Once that happens, you can try removing the hardcoded value and replacing it with a variable as follows -
Code: Select all
<cms:set my_uid='1234' />
<cms:pages masterpage="contrat-conferencier.php" custom_field="my_uid=<cms:show my_uid />">
    <cms:show k_page_name />
</cms:pages>

The second version above should work exactly the same as the first (please notice the use of double-quotes and <cms:show> while setting the 'custom_field' parameter.

If it works, I am sure you can adapt it to your specific use-case.

Hope this helps.
It works, but here's what I want to do :

The "contrats.php" page has the main "my_uid" field.
The "contrat-conferencier.php" page is there to generate a contract, taking all the information from the "contrats" page. The unique ID (contract number) of the "contrat-conferencier" is the same as the one in the "contrats.php" page, technically.

So what I try to do, is that if I am on the "contrats.php" page in the admin (of any of the entries), and that there's not already a page in the "contrat-conferencier.php" section that has a "my_uid" field that matches the current "contrats.php" entry on screen, a button should appear at the bottom saying "Create a sub-contract".
When I click on that button, it needs to create a new entry in the "contrat-conferencier.php" section, with "db_persist_form" (this part is already working fine).

If I already create the sub-contract earlier, that mean an entry in the "contrat-conferencier.php" section should have its "my_uid" field matching one of the entry in the "contrats.php" page.

So visiting a "contrats.php" entry with a "contrat-conferencier.php" entry that matches the "my_uid" field would display something else. It would display a button that says "Sub-contract already exists, click here to view it".

What I tried is to add this piece of code:

Code: Select all
<br><h4>Existing contract</h4>

<cms:pages masterpage="contrat-conferencier.php" custom_field="my_uid=<cms:show my_uid />">
<cms:form
    masterpage="contrat-conferencier.php"
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >
<a class="btn btn-primary" href="<cms:admin_link />">Sub-contract already exists, click here to view it</a>
<cms:no_results><cms:input name='submit' type="submit" id="convert" class="btn btn-primary" value="Create a sub-contract" /></cms:no_results>
<cms:if k_success>

    <cms:db_persist_form
    _invalidate_cache='0'
    _auto_title='1'
    my_uid=my_uid
    conferencier_dropdown="<cms:related_pages 'conferencier_dropdown' ids_only='1' />"
    langue=langue
    author=author

      />

</cms:if>

</cms:form>

</cms:pages>


I did this thinking that if a page returns no entry that matches the "my_uid" field, it would fit in the "no_results" code and would display that button. If there's is a matching entry, would display the other one.

It's hard to explain, but hopefully you will understand my issue.

Thanks!
Let us simplify the logic a bit and perhaps that would help -
Code: Select all
<cms:set contrat_existant="<cms:pages masterpage="contrat-conferencier.php" custom_field="my_uid=<cms:show my_uid />" count_only='1' />" />

<cms:if contrat_existant>
    .. display existing ..
<cms:else />
    .. create new ..
</cms:if>

In the code above we use 'show_count' param with <cms:pages> to return the count of contracts with the particular ID.
It will return 0 if no such contract is found and we can use that in the code that follows.

Hope this helps.
Great! It's working for that part :)

But I really don't understand some stuff.
Like why is this not working? There must be something I don't understand, because to me, it should be working.
This is in the "contrat-conferencier.php" page.

Code: Select all
<cms:show my_uid /> <!-- Shows the id of the contract -->
<cms:pages masterpage="contrats.php" custom_field="my_uid_hidden=<cms:show my_uid/>">
Number = <cms:show my_uid_hidden/>
</cms:pages>


I have created a new field. "my_uid_hidden", which is a regular text field.
Even if I enter an existing id in that field, which matches the one from the opened "contrat-conferencier.php" page, it's not showing anything.

I see the "my_uid" value being displayed on top of the page, but it looks like the custom_field part is not doing his job.
I'm just asking to show pages that has the field "my_uid_hidden" in "contrats.php" having the same content as the "my_uid" content of the "contrat-conferencier.php" page.

I've been spending hours on this...I have no idea why it's not working.
Seems ok to me. I don't see any reason for it not to work.
If your installation is online, PM me the FTP+Couch creds and I could take a look at it for you.
PM sent ;)
7 posts Page 1 of 1