by
KK » Wed Jun 24, 2015 11:12 pm
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.