Forum

Thread tagged as: Question

Input field in template which captures page name list detail page name

Hi

I'm using a list and detail page setup with a form on the detail page. I'm using the forms app for the forms on these detail pages.

Whenever a form is submitted I would like to be able to show which detail page the form has come from.

At the moment I am just showing the page slug.

On the detail layout I have the following code which is used to get the page slug.

<?php
PerchSystem::set_var('page', $_SERVER['SCRIPT_NAME']);
perch_content_custom('Form', array(
'template' => 'enquiry_form.html',
));
?>

Below is my enquiry form template and the hidden input field is the one which gives the page slug

        <perch:input type="hidden" label="Artist Name and Work" id="page" value="<perch:content id="page" escape="true" />" />

Would you know how I would go about getting the page title and then the name of the detail page i.e (Main page tile) "Product" (detail page title) "Product 1"

Thanks for any help with this.

Peter Meenagh

Peter Meenagh 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

$fields= perch_content_custom('Your content region', array(
    'skip-template' => 'true',
    ... add your filters ...
));
PerchSystem::set_vars($fields[0]);

Thanks for this Drew. What would into the Equiry Form template under the hidden input field?

At the moment I just have

<perch:input type="hidden" label="Artist Name and Work" id="page" value="<perch:content id="page" escape="true" />" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Give it the ID of any of your fields from the content region.

I've tried different IDs but it doesn't seem to be working. The field is just appearing blank in the form when I look at it through the forms app. I must be missing something.

I have entered this code into the product.detail.php layout

<?php $fields= perch_content_custom('Enquiry Form', array(
'skip-template' => 'true',
'filter'   => 'slug',
'match'    => 'eq',
'value'    => perch_get('s'),
'count'    => 1,
));
PerchSystem::set_vars($fields[0]);
?>

and in the enquiry_form.html template the hidden field is

<perch:input type="hidden" label="Artist Name and Work" id="title" value="<perch:content id="title" escape="true" />" />

I'm looking to get both the page title and the product title so will using 1 ID in this area do that?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> give you?

Hi Drew it shows this

ID  Value
perch_page_path /perch/core/apps/content/edit/index.php
_id 110
itemRowID   528
itemID  110
regionID    134
pageID  32
itemRev 16
itemOrder   1000
itemJSON    {"_id":"110"}
itemSearch  
perch_item_first    true
perch_item_last true
perch_item_zero_index   0
perch_item_index    1
perch_item_odd  
perch_item_count    1
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me what you're doing after the PerchSystem::set_vars ?

This code is in the product.detail.php layout

<?php $fields= perch_content_custom('Artist Name', array(
'skip-template' => 'true',
'filter'   => 'slug',
'match'    => 'eq',
'value'    => perch_get('s'),
'count'    => 1,
));
PerchSystem::set_vars($fields[0]);
?>

<div id="enquiry_drop">
                    <div class="arrow_up"><i class="fa fa-caret-up"></i></div>
                    <a name="enqmes" id="enqmes"></a>
                    <h4>Enquiry for <?php perch_pages_title(); ?> 
                        <?php
                            $result = perch_content_custom('Products', array(
                            'skip-template'=>true,
                            'filter'   => 'slug',
                            'value'    => perch_get('s'),
                            'count'    => 1,
                            ));
                            echo $result[0]['title'];
                        ?>
                      </h4>
                    <div id="enquiry_drop_inner">
                        <?php perch_content('Enquiry Form'); ?>
                    </div>
                </div><!--enquiry_drop-->

Then in the enquiry_form.html template this is all the code. The hidden input field is the one where I'm trying to pull in the list page title and the product detail title.

<perch:form id="artist_work_enquiry" method="post" app="perch_forms" action="#enqmes">

    <div class="leftcol">
        <div class="form_item">
            <perch:label for="yourname">Full Name<span class="red">*</span></perch:label>
            <perch:input type="text" id="yourname" required="true" label="Name" />
            <perch:error for="yourname" type="required"><p class="rederror">Please add your name</p></perch:error>
        </div>

        <div class="form_item">
            <perch:label for="email">Email Address <span class="red">*</span></perch:label>
            <perch:input type="email" id="email" required="true" label="Email" placeholder="you@youremailaddress.com" />
            <perch:error for="email" type="required"><p class="rederror">Please add your email address</p></perch:error>
            <perch:error for="email" type="format"><p class="rederror">Please check your email address</p></perch:error>
        </div>

        <div class="form_item">
            <perch:label for="tel">Telephone Number <span class="red">*</span></perch:label>
            <perch:input type="text" id="tel" required="true" label="Telephone Number" />
            <perch:error for="tel" type="required"><p class="rederror">Please add a contact telephone number</p></perch:error>
        </div>
    </div><!--leftcol-->

    <div class="rightcol">
        <div class="form_item_message">
            <perch:label for="message">Message <span class="red">*</span></perch:label>
            <perch:input type="textarea" id="message" required="true" label="Message" />
            <perch:error for="message" type="required"><p class="rederror">Please add your message</p></perch:error>
        </div>

        <perch:input type="hidden" label="Artist Name and Work" id="title" value="<perch:content id="title" escape="true" />" />

        <div class="human">
            <perch:label for="message">Are you Human?</perch:label>
            <perch:input type="text" id="banana" antispam="honeypot" />
        </div>

        <div class="form_submit">
            <perch:input type="submit" id="submit" value="Send"  class="submit" />
        </div>
    </div><!--rightcol-->


    <perch:success>
        <p>Thank you your message has been send. We will be in touch soon.</p>
    </perch:success>
</perch:form>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you replace:

<perch:input type="hidden" label="Artist Name and Work" id="title" value="<perch:content id="title" escape="true" />" />

with:

<perch:input type="hidden" label="Artist Name and Work" id="title" />