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

I was wondering if it would be possible to save a few databound forms at once, with one click.
This is what i've come up with so far:

Code: Select all
<cms:form method='get'>
<cms:pages masterpage="template.php">
   <cms:if k_success>
               <cms:form
                     masterpage='template.php'
                     mode='edit'
                     enctype='multipart/form-data'
                     method='post'
                     page_id=k_page_id
                     anchor='0'
                     >
                        <cms:db_persist_form
                           _invalidate_cache='0'
                           order=frm_order_bulk
                           
                        />
                        <cms:hide>
                           <cms:input type="bound" name="order"/>
                        </cms:hide>

                        
               </cms:form>
   </cms:if>
<cms:input type="text" name="order_bulk"/>
         </cms:pages>
<button type="submit">submit</button>
</cms:form>
         


Unfortunately it doesn't work and I don't know why.
Hi,

You are trying to nest one FORM within another - this is invalid HTML and no browser would support it.

For your use-case we don't actually require a databound-form. Please try the following where we use cms:db_persist (doesn't require a databound-form unlike cms:db_persist_form) -
Code: Select all
<cms:form method='get'>

    <cms:if k_success>
        <cms:pages masterpage="template.php">
       
            <cms:db_persist
                _masterpage=k_template_name
                _mode='edit'
                _page_id=k_page_id 
                _invalidate_cache='0'
               
                order=frm_order_bulk
            />

        </cms:pages>
    </cms:if>
   
    <cms:input type="text" name="order_bulk"/>
    <button type="submit">submit</button>
</cms:form>

As another example of bulk saving databound fields, please see the 'CSV Importer' (viewtopic.php?f=5&t=8803). The data comes from a csv file but the saving part remains the same as we used above (i.e. through cms:db_persist).

Hope it helps.
That didn't work, I can't change the values and save.

I was wondering though, can't this be done with AJAX?

I've been coding something up, every value is sent to the server, but not saved in the database. I think I need to chouchify the AJAX a bit :P

Code: Select all
<form class='forms' id='form1'>
     <!--form content-->
     <button type='submit' id='submit-button-1'>Submit</button>
</form>

<form class='forms' id='form2'>
     <!--form content-->
     <button type='submit' id='submit-button-2'>Submit</button>
</form>

<script>
                         $("#form2").on("submit", function() {
                          var $self = $(this);
                          var $form1 = $("#form1");
                          $.ajax({
                           url:'<cms:show k_page_link/>',
                           data: $form1.serialize(),
                           type: 'POST',
                           success: function(result) {
                             $self.submit();
                           }
                         });
                          return false;
                        });
                         </script>
That didn't work, I can't change the values and save.
Well, it definitely works for me :)
Trust me, I've tested the code.

So if it is not working for you, you need to further debug.
Perhaps your page has some 'required' field that is throwing an error and not allowing the page to get saved.

Please modify the code I originally posted to incorporate error/success reporting -
Code: Select all
<cms:form method='get'>

    <cms:if k_success>
        <cms:pages masterpage="template.php">
       
            <cms:db_persist
                _masterpage=k_template_name
                _mode='edit'
                _page_id=k_page_id 
                _invalidate_cache='0'
               
                order=frm_order_bulk
            >
           
                <cms:if k_error >
                    <font color='red'>ERROR:
                    <cms:each k_error >
                        <cms:show item /><br>
                    </cms:each>
                    </font>
                <cms:else />
                    <h3>Saved successfully: <cms:show k_page_name /></h3>
                </cms:if>
   
            </cms:db_persist>

        </cms:pages>
    </cms:if>
   
    <cms:input type="text" name="order_bulk"/>
    <button type="submit">submit</button>
</cms:form>

Please let me know what you see being reported.
Let us make the normal method work first and we'll tackle AJAX later.
4 posts Page 1 of 1