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

I want to make a user (account registered with Extended Users) as an author when they submitting post/article into my blog post.
Right now, in dropdown it always superadmin as author even the post submitted by another registered account at my site.

How to make this done?

here's my submission form:
Code: Select all
<cms:form style="padding: 15px 35px 45px;margin-top: 20px;
  background-color: #fff;
  border: 1px solid rgba(0,0,0,0.1); "
            masterpage='article.php'
            mode='create'
            enctype='multipart/form-data'
            method='post'
            id=author
            anchor='0'
            >
   
    <cms:if k_success >
       
        <cms:send_mail from='contact@xxx.com' to='noreply@xxx.com' reply_to=email subject='Feedback from your site'>
            The following is an email sent by a visitor to your site:
            <cms:show k_success />
        </cms:send_mail>

        <cms:db_persist_form
           k_publish_date='0000-00-00 00:00:00'
            _invalidate_cache='0'
            _auto_title='0'
        />

        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_page_link />
    </cms:if>

    <cms:if k_error >
        <div class="alert alert-danger fade in">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <div class="error">
            <cms:each k_error >
                <p><cms:show item /></p>
            </cms:each>
        </div>
        </div>
    </cms:if>
           


                <br>
                <div style="" class="wrapper">
                <label for="exampleInputPassword1">Judul Artikel</label>
            <cms:input style="height:45px" class="form-control" name='k_page_title' placeholder='Judul Artikel' type='bound' />
            <p></p>
               
                <label or="exampleInputPassword1">Kategori</label>
                <p>
                <cms:input style="height:45px" title="Choose one of the following..." class="form-group form-group" id="sel1" name="k_page_folder_id" placeholder='Kategori' type="bound" />
            <p></p>
            
                <label for="exampleInputPassword1">Konten Artikel</label>
                <p>
                Untuk menggunggah image pada body artikel, silahkan klik <a href="http://postimg.org" target="_blank">disini</a> lalu create img tag pada source HTML. <a href="http://www.w3schools.com/tags/tag_img.asp" target="_blank"><i class="fa fa-info-circle" aria-hidden="true"></i></a>
                </p>
                <cms:input style="height:45px;border: 1px solid #d4dbe0;border-radius: 4px;" class="form-control" name='blog_content1' placeholder='Tuliskan artikel kamu disini' type='bound' trust_mode='1'/>
            <p></p>            
            
                <label>Image artikel (max *500kb)</label>
                <cms:input style="height:45px" class="form-control" name='article_image1' placeholder='Image' type='bound' trust_mode='1' />
            <br>
                   
                <label for="exampleInputPassword1">Link Codepen (jika posting code)</label>
            <cms:input style="height:45px" class="form-control" name='codepen_link' placeholder='http://codepen.io/desain360/pen/OWyvvm' type='bound' />
            <p></p>
                   
                <label for="exampleInputPassword1">Link Download (in *zip)</label>
            <cms:input style="height:45px" class="form-control" name='download_link' placeholder='Link Download' type='bound' />
            <p></p>
               
                <cms:input class="btn btn-lg btn-primary btn-block" name="submit" type="submit" value="Submit"/>
               
                </div>
            </cms:form>

Thanks in advance.
Hi,

You can actually find this explained in the advanced tutorial (https://www.couchcms.com/docs/advanced-tutorial/).

Quoting from the mentioned tutorial, the 'notes.php' template (the equivalent of your blog template) had a relation field defined as follows (https://www.couchcms.com/docs/advanced- ... notes.html) -
Code: Select all
<cms:editable
    name='note_owner'
    type='relation'
    has='one'
    masterpage='users/index.php'
    label='Owner'
    required='1'
    no_guix='1'
/>

Next, in the databound form, this is how the logged-in user was set as the author of the note being created (https://www.couchcms.com/docs/advanced- ... -view.html) -
Code: Select all
<cms:if k_success>
    <cms:db_persist_form
        k_page_title=frm_name
        k_page_name="<cms:random_name />"
        note_pad=frm_pad
        note_owner=k_user_id
    />   
    ...
</cms:if>

As you can see, the "note_owner=k_user_id" statement above is the key to your solution.

I am sure you'll be able to adapt this to your use-case.
Hope it helps.
KK wrote: Hi,

You can actually find this explained in the advanced tutorial (https://www.couchcms.com/docs/advanced-tutorial/).

Quoting from the mentioned tutorial, the 'notes.php' template (the equivalent of your blog template) had a relation field defined as follows (https://www.couchcms.com/docs/advanced- ... notes.html) -
Code: Select all
<cms:editable
    name='note_owner'
    type='relation'
    has='one'
    masterpage='users/index.php'
    label='Owner'
    required='1'
    no_guix='1'
/>

Next, in the databound form, this is how the logged-in user was set as the author of the note being created (https://www.couchcms.com/docs/advanced- ... -view.html) -
Code: Select all
<cms:if k_success>
    <cms:db_persist_form
        k_page_title=frm_name
        k_page_name="<cms:random_name />"
        note_pad=frm_pad
        note_owner=k_user_id
    />   
    ...
</cms:if>

As you can see, the "note_owner=k_user_id" statement above is the key to your solution.

I am sure you'll be able to adapt this to your use-case.
Hope it helps.


It work like a charm. The key is, need little bit time to understand the code. Thanks KK you always the best. :D
You are welcome :)
4 posts Page 1 of 1
cron