Forum

Thread tagged as: Question, Runway

How to use an ID from one page on a form on another page - skip template?

Hi

I've setup a three page list and detail, for a careers section.

  • Page 1 list jobs
  • Page 2 show selected job
  • Page 3 shows job title (pulled in from page 2) and an application form

This works; but I'd like to send the job title along with the form submission

The id of the job title is id="job-role" I tried adding this to the form like this:

 <perch:input label="Job Reference" type="hidden" id="job-role" />

But unfortunately it doesn't work... The label appears in the forms control panel but the content is blank.

I think the way to do it would be to use skip-template, but I'm not sure how to implement it...

I'm using the following routes:

  • careers/[slug:s]
  • careers/[slug:s]/[apply:apply]

Here's the list and detail code:

     if (perch_get('apply')) {
       // Shows job title and an application form
       // URL: /careers/job-name-here/apply
       perch_collection('Careers', array(
      'template'   =>'job-form.html',
      'filter'   => 'slug',
      'match'    => 'eq',
      'value'    => perch_get('s'),
      'count'    => 1,   
      ));



    }

    elseif (perch_get('s')) {

      // Displays single job in careers collection filtered on slug
      // URL: /careers/job-name-here/

       perch_collection('Careers', array(
      'template'   =>'job-detail.html',
      'filter'   => 'slug',
      'match'    => 'eq',
      'value'    => perch_get('s'),
      'count'    => 1,                   
       ));

    }

    else {

         // Lists all jobs in careers collection
        // URL: /careers/
        echo'<div class="div pad main">';
        perch_collection('Careers', array(
        'template'   =>'job-list.html',            
        )); 


        }

Hope you can help

Stephen Meehan

Stephen Meehan 4 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you put this in your form, what happens?

<perch:input label="Job Reference" type="hidden" id="s" />

Hi Drew

Doesn't work unfortunately. label="Job Reference" is still blank when the form is submitted. Any further ideas?

There is something strange happening with the form, that may or not be related.

Just to recap:

  • Page 1: List jobs (URL: /careers)
  • Page 2: Show selected job (URL: /careers/job-name-here)
  • Page 3: Application form (URL: /careers/job-name-here/apply)

The form is on the third page of the list and detail setup.

The form doesn't validate. When I press submit the page reloads and goes back to page 1? Even though there are required fields on the form?

When the fields are filled in, the form successfully submits (shows up in the CMS) but the perch:success message isn't shown. The page reloads and goes back to page 1.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you view source, do you see the hidden field? Does it have a value?

Yes, this is what's in the source:

    <input id="form1_s" name="s" type="hidden">

This is what's in the template, for some reason it's different:

    <perch:input label="Job Reference" type="hidden" id="s" />

I've changed the template code back to:

  <perch:input label="Job Reference" type="hidden" id="job-role" />

It shows up in the source:

     <input id="form1_job-role" name="job-role" type="hidden">

I think the problem might be related to the way I'm adding the form to the page...

The if part of the statement uses a template called `job-form.html'

 if (perch_get('apply')) {          
       perch_collection('Careers', array(
      'template'   =>'job-form.html',
      'filter'   => 'slug',
      'match'    => 'eq',
      'value'    => perch_get('s'),
      'count'    => 1,   
      ));

job-form.html uses perch:template to pull the form in:

     <h1>You are applying for: <perch:content id="job-role" type="text" label="Position" html="false" title="true"          required="true" /></h1>   

      // This displays the job application form
     <perch:template path="content/forms/job-application-form.html" />

     <perch:content id="slug" for="job-role" type="slug" suppress="true" />

I'll try and add the form another way...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try:

<perch:input label="Job Reference" type="hidden" id="slug" />

Hi Drew

I got the form to submit the id="job-role"

I was able to modify something you helped me with previously.

I used perch_content_create to create the form region

   perch_content_create('Job application form', array(
     'template'  => 'forms/job-application-form.html',
     )); 

I then used skip-template in the if statement

       if (perch_get('apply')) {

       $result = perch_collection('Careers', array(
       'template'   =>'job-role-heading.html',
      'filter'   => 'slug',
      'match'    => 'eq',
      'value'    => perch_get('s'),
      'count'    => 1, 
      'skip-template' => true,
      'return-html' => true      
      ));
      echo $result['html'];

      // This displays the job form
      PerchSystem::set_vars($result[0]);
      perch_content_custom('Job application form');


    }

Within the job form I added this:

  <perch:input label="Job Reference" type="hidden" id="job-role" />

All the information from the form (including the hidden id) gets submitted.

I'm still having problems with the validation and the success message. The form still reloads the page without showing either validation errors or success message

As this is a different problem I'll create a new thread.