Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
Good evening.
I was wanting to add the value of the relational field to the k_page_title/ k_page_name in the db_persist_form to achieve the unique page generation as in the CSV module.

Relational field:
Code: Select all
<cms:editable name='noncoalcommodity' label="Non-coal Commodity" type='relation' masterpage='noncoal/commodity/commodity.php' has='one' />

Values in relational field are:
Coal
Clinkers, etc

Now from a DBF i want to be able to create a clonable page as:
Code: Select all
<cms:db_persist_form
                                        _invalidate_cache='0'
                                        _auto_title='0'
                                        k_page_title="<cms:show frm_k_page_title />"
                                        k_page_name="<cms:show k_page_title />_<cms:related_pages 'noncoalcommodity'><cms:show k_page_id /></cms:related_pages>"
                                    />


This is needed because the DBF will create pages like:
Coal_ASD
Clinker_ASD

With the unique page generation (as in CSV Importer Module) implemented, I am unable to create the cloned page. The k_page_name (using the code above) is set to the "_name" value but not something like Coal_name or Clinker_name (name keeps on changing and are common to coal/clinker etc).

Any help would be appreciated.

Regards
Image
where innovation meets technology
A little help would be really appreciated.
Image
where innovation meets technology
Hi,

In the following statement -
Code: Select all
k_page_name="<cms:show k_page_title />_<cms:related_pages 'noncoalcommodity'><cms:show k_page_id /></cms:related_pages>"

<cms:show k_page_title /> will try and show title of the page being visited in the browser (i.e. the page_view).
Similarly, the <cms:related_pages> will also try to find a page related to the same page being visited.

I suspect that is not what you want so please review your code.
@KK Sir,
Thanks for the response!

<cms:show k_page_title /> will try and show title of the page being visited in the browser (i.e. the page_view).
Similarly, the <cms:related_pages> will also try to find a page related to the same page being visited.


sir I have changed
Code: Select all
k_page_name=<cms:show frm_k_page_title />_<But what here>


But i am not able to understand what i need to put for the relation field. Also, if someone enters all caps in the text field then there is an error:
Name: Only Lowercase characters, numerals, hyphen and underscore permitted


This is my design:
related.png
related.png (4.52 KiB) Viewed 3572 times


The dropdown is the relational field and is defined in front end in DBF as:
Code: Select all
<div class="row">
    <div class="col-md-4 col-sm-4 col-xs-4">
        <label style="line-height: 30px;">Commodity</label>
        <div class="gxcpl-ptop-5"></div>
    </div>
    <div class="col-md-8 col-sm-8 col-xs-8">
        <cms:input name="noncoalcommodity" type="bound" class="form-control" />
        <div class="gxcpl-ptop-10"></div>
    </div>
</div>


While the text filed is defined as:
Code: Select all
<div class="input-group">
    <span class="input-group-addon" id="basic-addon1">
        <i class="fa fa-exchange"></i>
    </span>
    <cms:input name="k_page_title" type="bound" class="form-control text-uppercase" placeholder="Non-coal Loading Point" aria-describedby="basic-addon1" required="required" />
</div>


The Create form is:
Code: Select all
<cms:form
    masterpage=k_template_name
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
>
    <cms:if k_success >
        <cms:set my_template_name = 'noncoal/loadingpoint/loadingpoint.php' />
        <cms:set my_page_title = "<cms:show frm_k_page_title />" />

        <cms:php>
            global $CTX, $FUNCS;
            $name = $FUNCS->get_clean_url( "<cms:show my_page_title />" );
            $CTX->set( 'my_page_name', $name );
        </cms:php>

        <cms:set my_page_id = '' 'global' />
        <cms:pages masterpage=my_template_name page_name=my_page_name limit='1' show_future_entries='1'>
            <cms:set my_page_id=k_page_id  'global' />
        </cms:pages>

        <cms:if my_page_id=''>
            <cms:db_persist_form
                _invalidate_cache='0'
                _auto_title='0'
                k_page_title="<cms:show frm_k_page_title />"
                k_page_name="<cms:show frm_k_page_title />_<cms:related_pages 'noncoalcommodity'><cms:show k_page_id /></cms:related_pages>"
            />
           
            <cms:if k_success>
                <cms:set_flash name='submit_success' value='1' />
                <cms:redirect k_page_link />
            </cms:if>
        <cms:else />
            <div class="alert alert-danger">
                <strong>Oops! </strong>The non-coal loading point you want to create, already exists. You cannot recreate it.
            </div>
        </cms:if>                     

    </cms:if>
    <div class="panel panel-default">
        <div class="panel-heading text-center gxcpl-panel-bg">
            <strong>ADD NON-COAL LOADING POINT</strong>
        </div>
        <div class="panel-body">
            <cms:set submit_success="<cms:get_flash 'submit_success' />" />
            <cms:if submit_success >
                <div class="alert alert-success">
                    <strong>Success! </strong>Non-coal loading point added successfully.
                </div>
            </cms:if>
            <cms:if k_error >
                <div class="alert alert-danger">
                    <strong>Oops! </strong>The system has encountered error(s):
                    <div class="gxcpl-ptop-5"></div>
                    <cms:each k_error >
                        <cms:show item /><br>
                    </cms:each>
                </div>
            </cms:if>
            <div class="row">
                <div class="col-md-4 col-sm-4 col-xs-4">
                    <label style="line-height: 30px;">Commodity</label>
                    <div class="gxcpl-ptop-5"></div>
                </div>
                <div class="col-md-8 col-sm-8 col-xs-8">
                    <cms:input name="noncoalcommodity" type="bound" class="form-control" />
                    <div class="gxcpl-ptop-10"></div>
                </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">
                    <i class="fa fa-exchange"></i>
                </span>
                <cms:input name="k_page_title" type="bound" class="form-control text-uppercase" placeholder="Non-coal Loading Point" aria-describedby="basic-addon1" required="required" />
            </div>
        </div>
        <div class="panel-footer text-center">
            <button class="btn btn-danger btn-xs gxcpl-fw-500" type="submit">
                <i class="fa fa-save"></i> SAVE
            </button>
        </div>
    </div>
</cms:form>


Basic intention of the above code is to be able to stop creating cloned pages with same name or we can say create only one cloned page with one name and the name does not repeat.

Please suggest sir!

Regards
Image
where innovation meets technology
if someone enters all caps in the text field then there is an error:
Name: Only Lowercase characters, numerals, hyphen and underscore permitted

k_page_name (as opposed to k_page_title) accepts only a select subset of characters.
In your code, you are trying to set k_page_name with a value that is meant for k_page_title
Code: Select all
k_page_name="<cms:show frm_k_page_title />_

And hence the error.

In your code, you are already converting title to name via PHP so you can simply use that value i.e.
Code: Select all
k_page_name="<cms:show my_page_name />_


As for the main issue of getting the page_id of the related page -
your form contains a dropdown where the page would be selected by the user.
In the success condition, try getting the value being submitted through the dropdown - it should be the id you are looking for so nothing more needs to be done.

Does this help?
@KK Sir,
The actual issue is i am unable to get the single id.
Either I get all ids (of pages in the dropdown) or nothing at all.
Regards
Image
where innovation meets technology
Could you please take a look at the following post? -
viewtopic.php?f=4&p=35820#p35824

It is about retrieving value posted through a relation field using a PHP function (the actual function further goes on to convert the id to page_name, but I am sure you'll be able to adapt it for your need).

Hope this helps.
@KK Sir,
I couldnot get that implemented (the link you shared).
I did a different thing to get it working. I would want your view on the fact if the implementation is fine or not. Could there be a security leak coz of it.

This is what I did to get the value of the page_if of the commodity.php cloned pages
1. Add a hidden input field as:
Code: Select all
<cms:input name="commodity_related_id" id="commodity_related_id" type="text" hidden="hidden" />


2. Add the following script:
Code: Select all
<script type="text/javascript">
   $("#f_noncoalcommodity").change(function () {
       var selectedValue = $(this).val();
       $("#commodity_related_id").val($(this).find("option:selected").attr("value"))
   });
</script>

where, #f_noncoalcommodity=>is the id of the bound input of editable relation
and #commodity_related_id=>is the input field from #1
The script fills the value of the value attribute from the <option> tag into the input text field.

3. Finally to save the id of the related page, make the following changes in the cms:db_persist_form tag:
Code: Select all
<cms:db_persist_form
    _invalidate_cache='0'
    _auto_title='0'
    k_page_title="<cms:show frm_k_page_title />"
    k_page_name="<cms:show my_page_name />_<cms:show frm_commodity_related_id />"
/>

The k_page_name is set as:
Code: Select all
k_page_name="<cms:show my_page_name />_<cms:show frm_commodity_related_id />"


Though in my first post I was looking at achieving:
This is needed because the DBF will create pages like:
Coal_ASD
Clinker_ASD

But k_page_name="<cms:show my_page_name />_<cms:show frm_commodity_related_id />" also solves the issue for saving the k_page_name as a unique name, so i went with the id part than the name part.

Is there any type of issue with the code? If @KK Sir or anyone else could point out, I would be greatful.
Image
where innovation meets technology
I am surprised you weren't able to adapt the code I pointed to.
Anyway, the JS method is fine too.
@KK Sir,
Yes I could not. :( :?
Regards,
Aashish
Image
where innovation meets technology
10 posts Page 1 of 1