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

I am using the code to use repeatable regionns with DB_Persist that can be found in the Tips and tricks section of the forum.

It works almost perfectly for me.
The issue is that is always create an extra empty row in the repeatable region.

Here's what I'm doing :

(everything is done in the backend by the way, no front-end forms)
There's a page called "Proposals".
On this page, the user fills the form to create a proposal that can be sent to a prospect.
Once the Prospect agrees with the proposal, the user must convert the Proposal to a Contract.
So what I'm doing, is that I have added a button at the bottom of the page (in the theme template file of the Proposals page), that acts as a form that creates a new entry in the Contract page.

The Contract page has pretty much all the same fields (some fields are different, but most of it is the same) as the Proposals page. So I am using db_persist_form to sort of "clone" the proposals page, getting all the variables I need, and it creates a new entry in the Contract page.

Here's my code:

Code: Select all
  <cms:form 
    masterpage="contrats.php"
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

<cms:set nom="<cms:show k_page_name/>"/>
    <cms:pages masterpage="contrats.php" limit="1" page_name=nom>
    <cms:if nom!=''>
    <strong>Proposition déjà convertie en contrat</strong><br>
    <a href="<cms:admin_link />" class="btn btn-primary" style="background-color:green;"><cms:show_icon 'check' />Voir le contrat</a>
    </cms:if>
    <cms:no_results>
    <cms:input name='submit' type="submit" id="convert" class="btn btn-primary" style="background-color:green;" value="Convertir en contrat" />
    </cms:no_results>
    </cms:pages>


<cms:if k_success>
<cms:capture into='my_data' is_json='1'>
                <cms:show_repeatable 'block_evenement' as_json='1' />
            </cms:capture >
           
            <cms:capture into='my_data.' is_json='1'>
               {
                  "nom_evenement" : <cms:escape_json><cms:show nom_evenement /></cms:escape_json>,
                  "date_debut" : <cms:escape_json><cms:show date_debut /></cms:escape_json>,
                  "date_fin" : <cms:escape_json><cms:show date_fin /></cms:escape_json>,
                  "lieu_evenement" : <cms:escape_json><cms:show lieu_evenement /></cms:escape_json>
               }
            </cms:capture >

    <cms:db_persist_form
    _invalidate_cache='0'
    k_page_title=k_page_title
    contact_dropdown="<cms:related_pages 'contact_dropdown' ids_only='1' />"
    block_evenement=my_data
    conferencier_dropdown="<cms:related_pages 'conferencier_dropdown' ids_only='1' />"
    langue=langue
    contrat_status="Accepté"
    proposition_lien=my_uid
    author=author

      />
     
    <cms:redirect "<cms:pages masterpage="contrats.php" limit="1" page_name="<cms:show k_page_name/>" show_future_entries="1"><cms:admin_link /></cms:pages>"  />

</cms:if>

</cms:form>


Once I click the "Convert to contract" button, it successfully creates an entry in the Contract page. If I go in that newly created entry in the Contract page, I will see all the regions correctly cloned. The repeatable region will be copied too, but it always creates an extra row, with all the fields being empty, for some reasons.

I can't find why. Any ideas?

Thanks a lot!
Anyone?
Thank you!
2 posts Page 1 of 1