Vacancy request form for each subpage

I am looking for the best solution for my application form. There is a career page with subpages for each vacancy on these subpages should be a button which leads you to an application form on a new page.

That’s what the link’s should look like:

loremipsum.com/career
loremipsum.com/career/vacancytitle
loremipsum.com/career/vacancytitle/request-form

The first two pages already exist. Unfortunately, I do not know what is the best way to implement the third page with the form. The form itself is not a problem, but I dont want an extra page for each subpage where the form is in it. Or isnt that possible?

Thanks in advance for your help!

A custom route is what you want I think.
You can read more about routes here : https://getkirby.com/docs/developer-guide/advanced/routing

You could create a request form page and return that every time a user hits a url that matches your structure.

That looks good! Thanks!

But i have never done anything with routing. Do you have an example for my case?

You could do something like this

<?php
c::set('routes', [[
    'pattern' => 'career/(:any)/request-form',
    'action'  => function () {
        return page('request-form');
    }
]]);

Where request-form is the page with the actual form.
This is not tested but something similar to this should work in your case

This is my button:

<a href="<?= $pages->find('job-request')->url() ?>" 
class="button button-default button-big">FORM </a>

and the routing in my config is:

c::set('routes', array(
  array(
    'pattern' => 'career/(:any)/job-request',
    'action'  => function () {
      return page('job-request');
    }
  )
));

but the result than is

loremipsum.com/job-request

You have to manually construct the url if you want it to point to the pattern. I.e. use the url of the vacancy and add request-formmanually by string concatenation.

<a href="<?= $page->url().'/request-form' ?>" 
class="button button-default button-big">FORM </a>

Wow! Thanks, that is what im searching for.

Not working as desired now, but i think i can handle that :confused:

My problem now is to submit the title of the vacancy to the form. Something like page->parent doesnt work. Any ideas?

There are several ways to handle that. Your best option is to store the referring page in a session variable, I think.

Or you can parse the url and grab the “parent page” which is not really the parent page in your case.

Never did one of both possibilities :smiley:

What do you think is the best way?

fyi: i only want to display the vacancy title.

you can use the request path:
https://getkirby.com/docs/cheatsheet/request/path

Thanks a lot @texnixe!

For now i have the searched path. But how can i convert it to html for example?

You need to get the relevant part of the path, in your case it should be

$path = kirby()->request()->path()->nth(1)

This should return the uid of the vacancy page.
Then you can try to find the page:

if($vac = page('parent-page')->children()->find($path)) {
echo $vac->title();
}

Broke my path i think. I’ve tested another request but the result ist the same …

My code:

<?php $path = kirby()->request()->path()->nth(2); ?>
<?php if($vac = page('career')->children()->find($path)) {
  echo $vac->title();
  } ?>

The example of you shows me only the title of jobs

My current path is career/jobs/vacany/request

What do you get. if. you

dump($kirby->request()->path());

This:

Kirby\Request\Path Object
(
    [0] => karriere
    [1] => jobs
    [2] => sap-entwickler
    [3] => job-request
)

Well, the one with index 2. should. then be the one. you want to get, right? but it is not a subpage of careers, but. of jobs, it seems?

Well, the one with index 2. should. then be the one. you want to get, right?

Right. This is the title i want to display on the request page.

but it is not a subpage of careers, but. of jobs, it seems?

Right, too.

Then your code should look like. this:

<?php $path = kirby()->request()->path()->nth(2); ?>
<?php if($vac = page('career/jobs')->children()->find($path)) {
  echo $vac->title();
  } ?>

But, it that a multi language site?

It is working now. Thank you very much!