Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Still a bit lost I guess on the profile template but I just realized as I was working last night that I havent made the profile template clonable..I would like to let each user register to the website have their own unique profile page.....how would I go about that?Is it just setting the profile template to clonable? Ive also played with the avatar to get it on the profile page but should the avatar code go on users/index.php ? I noticed when I uploaded an avatar I did get an image showing however thats when I realized there are no separate profile pages and when I add the avatar whoever logs in sees it and doesnt have their own page...
1.I put the code for the avatar upload on profile.php and the only way I could upload an avatar was through the admin panel...I would like for an avatar upload button to be on the frontend for the user to upload his own avatar.....
Just not understanding how to give everyone their own unique profile page

As a test I just used my tablet to login under a different user and get :
Error: Tag "form"-page_id required
I think I can understand your confusion.
I'll try to put things in perspective for you. Perhaps it'll help.

OK, so for the time being forget the whole 'member' thing.
Let us concentrate only on DataBound Forms as without a good grasp on those we are not likely to go far.

I trust you have been through the docs on DBFs (http://www.couchcms.com/docs/concepts/d ... forms.html). If not, please do so before continuing with this discussion.

Let us assume we have a clonable template named 'blog.php' which has a single editable region named 'blog_content'.

You know very well how to create new blog pages from the admin-panel.
DBF gives you an alternative way to create/edit cloned pages from the front-end (i.e. your site). So, suppose we place the following code on 'index.php' (please note this is 'index.php' template and *not* 'blog.php') -
Code: Select all
<cms:form 
    masterpage='blog.php'
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

    <cms:if k_success >   
        <cms:db_persist_form />               
        <cms:redirect k_page_link />
    </cms:if>
   

    <label>Blog content</label>
    <cms:input name="blog_content" type="bound" />

    <button type="submit">Submit Blog post</button>

</cms:form>

When you visit index.php you'll see the form. Everytime you click submit, it results in the creation of a new blog post.

Please take a moment to think what is happening above - we are on a template named index.php but are creating cloned pages of another template named blog.php.

That is because the 'masterpage' parameter of cms:form is explicitly pointing to 'blog.php'.
That is the crux of the matter.

The index.php simply happens to be hosting the form that creates the blog posts.
Template blog.php definitely has to be clonable (because a new page gets created at every form submission) but there is no need for such restriction on index.php (it is just a hosting container).

Now if you understood that let us modify the code above to edit existing blog posts (instead of creating as we have done so far). Take a look at the following form -
Code: Select all
<cms:form 
    masterpage='blog.php'
    mode='edit'
    page_id='846'
    enctype="multipart/form-data"
    method='post'
    anchor='0'
    >
   
    <cms:if k_success >
        <cms:db_persist_form />
        <cms:redirect k_page_link />
    </cms:if> 

    <label>Blog content</label>
    <cms:input name="blog_content" type="bound" />

    <button type="submit">Edit Blog post</button>
   
</cms:form>

The form above is very similar to the one we used above. The only difference is the mode='edit' and the 'page_id' parameters.

So, again assuming the form is placed in index.php, everytime you click on the form it will edit a blog page with the id '846'. Not very useful because we are using a fixed ID. If, however, we could somehow supply the page_id dynamically e.g. as follows
Code: Select all
    ...
    mode='edit'
    page_id=my_page_id
    ...

- the code above will edit the blog post that is specified through the variable named 'my_page_id'. So if the value within the variable 'my_page_id' changes, the same form in the same template (i.e. index.php) will be able to edit different blog posts.

If you are with me so far and could understand what is happening, let us make our last and final move.

Assume that 'index.php' is 'profile.php' (i.e. a simple non-clonable template).
Also assume that the form code within it is now -
Code: Select all
<cms:form 
    masterpage=k_member_template
    mode='edit'
    page_id=k_member_id
    enctype="multipart/form-data"
    method='post'
    anchor='0'
    >
    ..
    ..

The 'masterpage' parameter is now pointing to a variable named 'k_member_template' which always contains the name of the template you used to create member accounts (e.g. 'members/index.php').

The 'page_id' is now pointing to a variable named 'k_member_id' which always contains the ID of the cloned page that represents the actual account of the currently logged-in user.

Can you make out what this form is going to edit?
Answer: The account of the currently logged-in user (i.e. the cloned page representing her account).

So I think now you can see that when a logged-in user accesses profile.php, the info she sees there in the form belongs exclusively to her. In other words, every user *has* a unique profile page.

If you were to define a 'securefile' region in 'members/index.php' (the template used for accounts), and then place it in the form shown above in 'profile.php' and the logged-in user uploads an image through it - the image will be saved in her account. A different logged-in user doing the same will have the image saved in her account.

I do hope things are clearer now to you.
That is the best I could do, my friend :)

Please take a look at the sample code that comes with the members module and I think you'll see that it already does what you want.
Thank you KK
your information makes sense and I understand it much better now
Ok I m getting somewhere but the only way I was able to give an option for a member to upload their own avatar was like this by adding to the databound form on profile.php:
Code: Select all
  <cms:form 
        masterpage=k_user_template
        mode='edit'
        page_id=k_user_id
        enctype="multipart/form-data"
        method='post'
        anchor='0'
        >
       
        <cms:if k_success >
            <cms:db_persist_form />

            <cms:if k_success >
                <cms:set_flash name='success_msg' value='1' />
                <cms:redirect k_page_link />
            </cms:if>
        </cms:if> 
       
        <cms:if k_error >
            <font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
        </cms:if>
       
       
        DisplayName:<br />
        <cms:input name='k_page_title' type='bound' /><br />

        E-mail:<br />
        <cms:input name='extended_user_email' type='bound' /><br />

        New Password: (If you would like to change the password type a new one. Otherwise leave this blank.)<br />
        <cms:input name='extended_user_password' type='bound' /><br />

        Repeat Password:<br />
        <cms:input name='extended_user_password_repeat' type='bound' /><br /> 

        Upload an Avatar:<br />
        <cms:editable name='avatar' required='1' allowed_ext='jpg, jpeg, png, gif' max_size='2048' type='securefile' width='100' height='100' quality='100'   use_thumb_for_preview='1' /><cms:input name="avatar" type="bound" /><br />
         
      <input type="submit" name="submit" value="Save"/>   
       
   
</cms:form>   

<!-- give an option to logout -->
    <a href="<cms:logout_link />">logout</a> 

</form> <!-- /#commentform -->
          <cms:pages masterpage=k_user_template id=k_user_id>
   <cms:show_securefile 'avatar' >
    <cms:if file_is_image >
        <a href="<cms:cloak_url link=file_id />"><img src="<cms:cloak_url link=file_id  />" /></a><br />
       
   
    </cms:if>
</cms:show_securefile>
   </cms:pages>
         </section> <!-- /#ccr-contact-form -->



However I have this code on Index.php(users):
Code: Select all
 <cms:editable name='avatar' label='avatar' allowed_ext='png, jpg, jpeg' max_size='2048' type='securefile' width='100' height='100' quality='100'    />


I am able to upload an avatar from member profile template now but it seems to be of course going in 2 places to the admin panel and the only way I can make it work is by adding the editable region to the databound form as well....Is there a way to link it to the index.php in dataform without having to run the editable region in it?
All the editable regions need to be defined *only* in the index page - the profile page is just a shim.

Place this in members/index.php
Code: Select all
<cms:editable 
    name='avatar'
    required='1'
    allowed_ext='jpg, jpeg, png, gif'
    max_size='2048'
    type='securefile'
    width='100'
    height='100'
    quality='100'   
    use_thumb_for_preview='1' />


Place this in profile.php
Code: Select all
Upload an Avatar:<br />    
<cms:input name="avatar" type="bound" /><br />

Hope it helps.
I had tried that and recieved an error that the name "avatar" wasnt found in database....I think that was it.....Somehow I deleted the editable region off the index.php and left it on profile.php and its working..Lol I hope thats good
6 posts Page 1 of 1