Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
Hi,

A question regarding sending informations from member area using databound form. I have a situation in which users can send monthly the following data from they user account: apartment block, entrance, apartment, date, index1, index2. But as the first 3 info is already available since account creation and users being logged into their account it would be strange and unnecessary to ask users to enter again that info.
So is there any possibility to send the already available user infos automatically and ask user to enter only the rest of infos in order to send them via databound form?
Hi,

We can pass data directly to cms:db_persist_form (as opposed to through form fields) e.g.
Code: Select all
<cms:db_persist_form 
    apartment_block='lorem'
    entrance='ipsum'
    apartment='dipsum'
/>
In the code above the editable regions named 'apartment_block', 'entrance' and 'apartment' will always get the specified values.

Of course instead of the hard-coded values, as in the example above, we can use variables to pass the values.

I think you can figure out from here how to take values from the logged-in user's account and then pass them on to cms:db_persist_form. The values that are not associated with the user account can be collected via bound fields in the usual manner.

Hope this helps.
KK wrote: Hi,
I think you can figure out from here how to take values from the logged-in user's account and then pass them on to cms:db_persist_form.

Unfortunately I have no idea, KK :( If anyone can help me with this, I will be grateful.
That is not a problem, @atisz :)
Can you please your code as it exists right now?
KK wrote: That is not a problem, @atisz :)
Can you please your code as it exists right now?

Of course, KK. For now my code contained in consumption.php is pretty much the one you have provided in your databound demo, adapted to my needs.
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:template title='Consumption' clonable='1'>
   <cms:editable name='apartment_block' required='1' type='text' />
   <cms:editable name='entrance' required='1' type='text' />
   <cms:editable name='apartment' required='1' type='text' />
   <cms:editable name='date' required='1' type='text' />
   <cms:editable name='index1' required='1' type='text' />
   <cms:editable name='index2' required='1' type='text' />
</cms:template>
<!doctype html>
<html>
<head>
   <meta charset="utf-8">
   <meta content="width=device-width, initial-scale=1.0" name="viewport">
   <title>User consumtion</title>
   <link href="css/bootstrap.min.css" media="screen" rel="stylesheet">
   <link href="css/styles.css" media="screen" rel="stylesheet">
</head>
<body>
    <cms:member_check_login />
    <cms:if k_member_logged_out >
        <cms:redirect "<cms:member_login_link />" />
    </cms:if>
<div class="container">
   <div class="header">
      <h3>Enter your consumption</h3>
   </div>
   <div class="body">
        <cms:set submit_success="<cms:get_flash 'submit_success' />" />
        <cms:if submit_success >
            <div class="alert alert-success"><strong>Success:</strong> Your consumption has been sent successfully.</div>
        </cms:if>
      <cms:form
            masterpage=k_template_name
            mode='create'
            enctype='multipart/form-data'
            method='post'
            anchor='0'
            >
            <cms:if k_success >
                <cms:db_persist_form
                    _invalidate_cache='0'
                    _auto_title='1'
               apartment_block='lorem'
                entrance='ipsum'
                apartment='dipsum'
                />
                <cms:if k_success >
                    <cms:set_flash name='submit_success' value='1' />
                    <cms:redirect k_page_link />
                </cms:if>
            </cms:if>
            <cms:if k_error >
                <div class="alert alert-danger"><strong>Error:</strong>
                    <cms:each k_error >
                        <br><cms:show item />
                    </cms:each>
                </div>
            </cms:if>

         <div class="form-group <cms:if k_error_date >has-error</cms:if>">
            <label class="control-label" for="date">Date <span class="required">*</span></label>
            <cms:input class="form-control" id="date" name="date" type='bound' value=""  />
         </div>
         <div class="form-group <cms:if k_error_index1 >has-error</cms:if>">
            <label class="control-label" for="index1">Index 1 <span class="required">*</span></label>
            <cms:input class="form-control" id="index1" name="index1" type='bound' value=""  />
         </div>
            <div class="form-group <cms:if k_error_index2 >has-error</cms:if>">
            <label class="control-label" for="index2">Index 2</label>
            <cms:input class="form-control" id="index2" name="index2" type='bound' value=""  />
         </div>
           
            <cms:if "<cms:not submit_success />" >
                <button class="btn btn-primary" type="submit">Send consumption</button>
            </cms:if>
           
      </cms:form>
   </div>
   
</div>
</body>
</html>
<?php COUCH::invoke(); ?>

In the above template I have an editable named "date", however I think I should probably use instead of this the page publish date.
Apologies for the delay in my reply, atisz (am having an unusually busy week).
As promised, here is the solution.

Members, as you know, are just cloned pages and so we can use our trusty cms:pages tag to get data from their editable regions.

Assuming that your member template has regions named 'apartment_block', 'entrance' and 'apartment', the following code would store data of the currently logged-in member into some global variables -
Code: Select all
<cms:pages masterpage=k_member_template id=k_member_id>
   // we have all data about the current member here ..
 
   <cms:set my_apartment_block=apartment_block 'global' />
   <cms:set my_entrance=entrance 'global' />
   <cms:set my_apartment=apartment 'global' />
</cms:pages>

Now we can use the variables we set above to pass data on to the databound-form, as discussed before -
Code: Select all
<cms:db_persist_form 
    _invalidate_cache='0'
    _auto_title='1'
    apartment_block=my_apartment_block
    entrance=my_entrance
    apartment=my_apartment
/>

And that's it.

Full code of your template now becomes -
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:template title='Consumption' clonable='1'>
   <cms:editable name='apartment_block' required='1' type='text' />
   <cms:editable name='entrance' required='1' type='text' />
   <cms:editable name='apartment' required='1' type='text' />
   <cms:editable name='date' required='1' type='text' />
   <cms:editable name='index1' required='1' type='text' />
   <cms:editable name='index2' required='1' type='text' />
</cms:template>
<!doctype html>
<html>
<head>
   <meta charset="utf-8">
   <meta content="width=device-width, initial-scale=1.0" name="viewport">
   <title>User consumtion</title>
   <link href="css/bootstrap.min.css" media="screen" rel="stylesheet">
   <link href="css/styles.css" media="screen" rel="stylesheet">
</head>
<body>
    <cms:member_check_login />
    <cms:if k_member_logged_out >
        <cms:redirect "<cms:member_login_link />" />
    </cms:if>
<div class="container">
   <div class="header">
      <h3>Enter your consumption</h3>
   </div>
   <div class="body">
        <cms:set submit_success="<cms:get_flash 'submit_success' />" />
        <cms:if submit_success >
            <div class="alert alert-success"><strong>Success:</strong> Your consumption has been sent successfully.</div>
        </cms:if>
       
        <cms:pages masterpage=k_member_template id=k_member_id>
           // we have all data about the current member here ..
           
           <cms:set my_apartment_block=apartment_block 'global' />
           <cms:set my_entrance=entrance 'global' />
           <cms:set my_apartment=apartment 'global' />
        </cms:pages> 
     
      <cms:form
            masterpage=k_template_name
            mode='create'
            enctype='multipart/form-data'
            method='post'
            anchor='0'
            >
            <cms:if k_success >
                <cms:db_persist_form
                    _invalidate_cache='0'
                    _auto_title='1'
                    apartment_block=my_apartment_block
                    entrance=my_entrance
                    apartment=my_apartment
                />
                <cms:if k_success >
                    <cms:set_flash name='submit_success' value='1' />
                    <cms:redirect k_page_link />
                </cms:if>
            </cms:if>
            <cms:if k_error >
                <div class="alert alert-danger"><strong>Error:</strong>
                    <cms:each k_error >
                        <br><cms:show item />
                    </cms:each>
                </div>
            </cms:if>

         <div class="form-group <cms:if k_error_date >has-error</cms:if>">
            <label class="control-label" for="date">Date <span class="required">*</span></label>
            <cms:input class="form-control" id="date" name="date" type='bound' value=""  />
         </div>
         <div class="form-group <cms:if k_error_index1 >has-error</cms:if>">
            <label class="control-label" for="index1">Index 1 <span class="required">*</span></label>
            <cms:input class="form-control" id="index1" name="index1" type='bound' value=""  />
         </div>
            <div class="form-group <cms:if k_error_index2 >has-error</cms:if>">
            <label class="control-label" for="index2">Index 2</label>
            <cms:input class="form-control" id="index2" name="index2" type='bound' value=""  />
         </div>
           
            <cms:if "<cms:not submit_success />" >
                <button class="btn btn-primary" type="submit">Send consumption</button>
            </cms:if>
           
      </cms:form>
   </div>
   
</div>
</body>
</html>
<?php COUCH::invoke(); ?>

Hope this helps.
Do let us know.

Thanks.
KK wrote: Apologies for the delay in my reply, atisz (am having an unusually busy week).
As promised, here is the solution.
Hope this helps.
Do let us know.


No problem, KK! And yes, it helped me to understand how things work with this, now I can use my form to submit all the required info. Thank you for the great support!
Hi,

As I have mentioned in one of my posts above, in my template I have included an editable named "date" and was thinking about using this editable or couch generated publish date. Finally I decided to use couch publish date, this way when sending info the user shouldn't enter the date manually and also (what's important in this case) the date should be the real sending date not some date chosen out of my needed/accepted date range.
I also need a page to display the submitted data filtered not only by apartment_block, entrance..., but by publish date too. I have implemented the solution found in this topic http://www.couchcms.com/forum/viewtopic.php?f=8&t=7620 but just with half success as I couldn't find any reference in forum's posts regarding filtering data sent between a start date and an end date, using publish date.
I would need 2 select boxes for choosing the start date and end date, beside the other select boxes for apartment_block, entrance....... and so on.
So, some sample would be great and highly appreciated :)
Hi,

If you are using the publish_date, cms:pages tag supports filtering on that using 'start_on' and 'stop_before' parameters (please see http://www.couchcms.com/docs/tags-reference/pages.html).

You can use the submitted values of the date dropdowns to set the two mentioned parameters.
KK wrote: Hi,

If you are using the publish_date, cms:pages tag supports filtering on that using 'start_on' and 'stop_before' parameters (please see http://www.couchcms.com/docs/tags-reference/pages.html).

You can use the submitted values of the date dropdowns to set the two mentioned parameters.

@KK I really don't know how to do that. Anyway, I have found another solution in this post http://www.couchcms.com/forum/viewtopic.php?f=4&t=8211&p=14665&hilit=start_on#p14665 , which is not offering any flexibility for managing dates (for checking previous months submissions), but somehow might be the right solution for me. Thanks for your help.
10 posts Page 1 of 1
cron