klixx
September 17, 2018, 11:31am
1
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.
klixx
September 17, 2018, 11:54am
3
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
klixx
September 17, 2018, 1:49pm
5
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
texnixe
September 17, 2018, 2:49pm
6
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-form
manually by string concatenation.
<a href="<?= $page->url().'/request-form' ?>"
class="button button-default button-big">FORM </a>
klixx
September 18, 2018, 7:44am
7
Wow! Thanks, that is what im searching for.
Not working as desired now, but i think i can handle that
My problem now is to submit the title of the vacancy to the form. Something like page->parent doesnt work. Any ideas?
texnixe
September 18, 2018, 8:06am
8
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.
klixx
September 18, 2018, 8:54am
10
Never did one of both possibilities
What do you think is the best way?
fyi: i only want to display the vacancy title.
texnixe
September 18, 2018, 9:23am
11
klixx
September 18, 2018, 9:35am
12
Thanks a lot @texnixe !
For now i have the searched path. But how can i convert it to html for example?
texnixe
September 18, 2018, 9:40am
13
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();
}
klixx
September 18, 2018, 10:13am
14
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
texnixe
September 18, 2018, 10:24am
15
What do you get. if. you
dump($kirby->request()->path());
klixx
September 18, 2018, 10:38am
16
This:
Kirby\Request\Path Object
(
[0] => karriere
[1] => jobs
[2] => sap-entwickler
[3] => job-request
)
texnixe
September 18, 2018, 10:48am
17
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?
klixx
September 18, 2018, 10:49am
18
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.
texnixe
September 18, 2018, 10:51am
19
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?
klixx
September 18, 2018, 2:42pm
20
It is working now. Thank you very much!