Problems, need help? Have a tip or advice? Post it here.
12 posts Page 1 of 2
Hi there,
I am in a bit hurry and within a genuine problem. Need help!

I am using a separate PHP script for storing the form data using cms:db_persist into a clonable template. Certainly there has been introduced a new repeatable region which holds two editable regions of text type. Please tell me how can I store the repeatable regions data from the form using db_persist tag.
Code: Select all
<cms:db_persist
      _masterpage='surveyForm.php'
      _mode='create'
      _invalidate_cache='0'
      _autotitle='0'
      k_page_title=randomName
      k_page_name=randomName
      account=account
      service_category=service_category
      sub_service_category=sub_service_category
      responsedetails=f_responsedetails
/>

in above tag, responsedetails is the repeatable region. Please tell me a trick to store this data. Tried too find a lot but posting the query was last option.

Hello. If you are using <cms:input /> in the form, then input value is available after submit as frm_inputnamehere. Please try this. Essentially, if your input name is f_responsedetails, then it would be like this in db_persist tag: responsedetails=frm_f_responsedetails.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate

@trendoman, you are, of course, right about the 'frm_' prefix but it won't work as expected with repeatable_regions I am afraid.
Reason being, the value submitted by repeatable region is a complex structure and requires a helper tag (cms:show_repeatable) to be shown.

@shubhamSonar, repeatable-region can only be used on the front-end in a 'bound' manner (i.e. it needs to be within a databound form and needs to have a corresponding real editable-region in the admin-panel). So, if instead of <cms:persist>, you were to use <cms:persist_form /> instead, the DBF form would automatically persist the submitted values of the repeatable-region for you.

Could you please tell me why you chose to use cms:persist instead of the usual cms:persist_form (when you are already using a databound form)?

Sure, I totally missed the repeatable thing. Appreciate the heads-up :)
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate

Hi KK, I am not using databound forms, I am just using cms:form to call a simple php form post action. I did this cause I am doing some serious integration with a cloud API due which I was needing a lot of complex PHP scripting due which I used $_
POST -> $CTX-Set and Finally cms:db_persist. Please help me out to wrap up data from simple html input tags to a PHP array such that I can pass it to db_persist.

for convenience:

Depending upon some selected drop-down values, some respective question are fetched from a cloud API to be answered by the user which are again send back to same API and in Parallel a PDF is generated and mailed to someone.

So this 'question and answers' are dynamically generated and also inside the repeatable region. I guess KK, you can help me out with this stuff. Would very thankful for it though.

I am sorry Shubham but we cannot *set* a repeatable-region directly through parameters of cms:persist.
The only way of setting repeatable-region is by making it 'bound' (this exposing its GUI) and then using cms:persist_form to save it automatically,

Please try refactoring your code from
Code: Select all
<cms:form>
    ..
    <cms:db_persist
          _masterpage='surveyForm.php'
    />
    ..
</cms:form>

to make it a databound form as follows -
Code: Select all
<cms:form masterpage='surveyForm.php'>
    ..
    <cms:db_persist_form />
    ..
</cms:form>

You can then expose the repeatable-region on the frontend (please see viewtopic.php?f=4&t=10784#p27418).

Hope it helps.

Ok will this be possible then that I store the question and answers in other clonable template with some relation to the other details. I am completely unaware about how to add relations even from the db_persist tag. I guess you are getting what am trying to say:

Details (Parent Template):

(Child Template)
question1
answer1

question2
answer2


I guess this can be done But I don't know the way!

It's been discussed many times, please use a little search :)
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate

Hi there,
I have sorted out a way to do so with relationships. Can I put up multiple Page Ids into a relation field using db_persist,
currently I am able to insert single but is there a way to put multiple of them using some PHP array. Here is a part of my code:
Code: Select all
<cms:repeat count="<cms:show questioncount />" startcount='0'>
   <cms:php>
      global $CTX;
      
      $questionNo = question."<cms:show k_count />";
      $answerNo = answer."<cms:show k_count />";
      $question = $_POST["$questionNo"];
      $answer = $_POST["$answerNo"];
      
      $CTX->set('question',$question);
      $CTX->set('answer',$answer);
      $CTX->set('randomName',"<cms:random_name />");
   </cms:php>
   <cms:db_persist
      _masterpage='surveyForm.php'
      _mode='create'
      _invalidate_cache='0'
      _autotitle='0'
      k_page_title=randomName
      k_page_name=randomName
      question=question
      answer=answer
   >
   
   <cms:if k_error >
        <font color='red'>ERROR:
        <cms:each k_error >
            <cms:show item /><br>
        </cms:each>
        </font>
    <cms:else />
   
   <cms:set last_insert_id="<cms:show k_last_insert_id />"  />
   <cms:show k_last_insert_page_name />
   
   <cms:db_persist
      _masterpage='surveyResponses.php'
      _mode='create'
      _invalidate_cache='0'
      _autotitle='0'
      k_page_title=last_insert_id
      k_page_name=last_insert_id
      response_details=last_insert_id
      account=account
      service_category=service_category
      sub_service_category=sub_service_category
      email=email
   />
       
       
    </cms:if>
</cms:db_persist>
</cms:repeat>


I want to bring the second db_persist tag out of the cms:repeat tag wherein want to store all the insert ids from the repeat tag into the response_details relation field in second db_persist tag. Thanks in advance :)
12 posts Page 1 of 2
cron