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

I have a list that displays the cloned pages from a template.

The list had an delete button. This button is used to open a bootstrap modal (i am using v3.3.7).

I have a single modal code that will trigger a modal whenever any delete button from the list is clicked. I want to be able to pass the k_page_id of the page to the modal so that I can use it to set a variable using cms:set. And then use the cms:set value to the page_id of the delete form.

The code looks like:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:template title='Modal' parent='_test_' />
<!DOCTYPE html>
<html>
<head>
   <title></title>
   <link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.css">
</head>
<body>
   <cms:pages masterpage="department/department.php">
   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="<cms:show k_page_id />">Open <cms:show k_page_title /></button><br>

   </cms:pages>


   <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
      <div class="modal-dialog" role="document">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
               <h4 class="modal-title" id="exampleModalLabel">New message</h4>
            </div>
            <div class="modal-body">
               // Show data-whatever value in a variable
            </div>
            <div class="modal-footer">
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
               <button type="button" class="btn btn-primary">Send message</button>
            </div>
         </div>
      </div>
   </div>

   <script type="text/javascript" src="../assets/js/jquery-2.0.0.js"></script>
   <script type="text/javascript" src="../assets/js/bootstrap.js"></script>
   <script type="text/javascript">
      $('#exampleModal').on('show.bs.modal', function (event) {
         var button = $(event.relatedTarget) // Button that triggered the modal
         var recipient = button.data('whatever') // Extract info from data-* attributes
         var modal = $(this)
         modal.find('.modal-title').text('New message to ' + recipient)
      })
   </script>

</body>
</html>
<?php COUCH::invoke( ); ?>


the line:
modal.find('.modal-title').text('New message to ' + recipient)

passes the value to the modal. but i want to use that value in <cms:form... mode='edit' page_id=recipient....>...</cms:form>

How can this be done?

Regards,
GenXCoders
Image
where innovation meets technology
There would be two parts to the solution -
1. On the backend, A regular Couch template that generates the form (DataBound) and process any result posted to it.
2. On the frontend, some code that calls the above mentioned template via AJAX (passing the page_id *and* a nonce), receives it and shows it at the proper place in the modal. It should also hook up the 'submit' button to post back data to the same template to process the form submission.

I suppose you need some pointers only about the second point (the first is staple DBF). If so, perhaps our cart example would help where we show a backend template (cart modal) inside a popup.

The code you are using could become something like this -
Code: Select all
<script type="text/javascript">
  $('#exampleModal').on('show.bs.modal', function (event) {
     var button = $(event.relatedTarget) // Button that triggered the modal
     
     var page_id = button.data('page-id') // Extract info from 'data-page-id' attribute
     var nonce = button.data('nonce') // Extract info from 'data-nonce' attribute
     
     // use AJAX here to call the backend template with the required params
     
     // and display the received result at the proper place in the modal
     var modal = $(this)
     modal.find('.modal-body').....
  })
</script>

Hope this helps.
@KK sir.
I will try the solution you have mentioned and get back asap.
Thanks for tje reply.
Regards,
Aashish
Image
where innovation meets technology
Couch Cart thing confused me a little.

But I am creating the nounce as:
(Just stripped the code to the button and updated the button from couch cart)
Code: Select all
<cms:pages masterpage="department/department.php">
         <cms:set page_to_delete=k_page_id scope='global' />
         <cms:set my_action="delete_page_<cms:show page_to_delete />" scope='global' />
         <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-page-id="<cms:show k_page_id />" data-nonce="<cms:create_nonce my_action />" style="width: 200px;">
            <cms:show k_page_title /> <br><small><em>{Page Id::<cms:show k_page_id />}</em></small>
         </button>
         <div style="padding-top: 10px;"></div>
      </cms:pages>

Is this fine?

Now my DBF are actually custom routes base. Will that be fine, or do i create separate files sir?

Regards,
Aashish
Image
where innovation meets technology
To be secure, the nonce has to be unique for each accessed URL - this can be done by adding the page_id to it.
@KK Sir.
Good evening.

I followed your post viewtopic.php?f=4&t=8087 to generate the nonce. And the same does generate.

Here is a snap shot:
nonce.png
nonce.png (14.54 KiB) Viewed 3040 times


So basically I am able to generate different nonce.

But when you said this:
To be secure, the nonce has to be unique for each accessed URL - this can be done by adding the page_id to it.

I checked the modal. In the modal I have appended the nonce just to display it. And I found that the nonce of button named "1" is showing on each modal.

So I am working on the same now. Will get back shortly.

Regards,
Aashish.
Image
where innovation meets technology
@KK Sir,

I have been able to generate the modal and display the page to edit into it.

But now what happens is that there are two inputs being generated for the k_nonce. Both have the same value, name and id.

When I save the form it sends me to a page, stating that security tokens do not tally with a link in the bottom that send to the admin page (i.e. couch panel).

What do i do?

Regards,
Aashish
Image
where innovation meets technology
I'm trying to get data from a couch page, into a modal (using UIKit 3.2.6 as my frontend).
I only have a list page on my website and want the detail page to open in a custom designed modal, so I will keep following this post in hopes to "steal" some code and make my project work :)
Keep it up 8-)
---
You live many times, but only ever remember your lives.length - 1
---
Image
8 posts Page 1 of 1