Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
3305 Zobrazení

I have a jobs page on my website with the exact same job being offered in 10 cities. Rather than create a page and form for each city, I'd like to simply append a variable to the link - eg. www.example.com/job_application?city=toronto


I'd like to have the "job_application" page contain a form that simply reads (perhaps via javascript) the variable and submits it in a "city" field on the form to my inbox upon successful submission. 


Possible?

Avatar
Zrušit
Nejlepší odpověď

Hi,

Yes, it's definitely possible to achieve this in Odoo. Here's a general approach you could take:

->Create a new form view for your job application form. In this form view, add a new field for the city (e.g. city_id), and set the invisible attribute to 1 so that it's not displayed on the form.

<template id="job_application_form" name="Job Application Form">


    <form id="job_application" method="post">


        <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>


        <input type="hidden" name="city" t-att-value="request.params.get('city')"/>


        <input type="text" name="name" placeholder="Name"/>


        <input type="email" name="email" placeholder="Email"/>


        <textarea name="message" placeholder="Message"></textarea>


        <button type="submit">Submit</button>


    </form>


</template>

->Create a new controller method or server action to handle the job application form submissions. In this method, you can retrieve the value of the city parameter from the request URL using request.params.get('city'). You can then set the value of the city_id field on the new record to this value.

@http.route('/job_application', type='http', auth='public', website=True)
def job_application(self, **kw):
city = request.params.get('city')
values = {
'city_id': city
}
# create a new job application record
application = request.env['job.application'].sudo().create(values)
# redirect the user to a thank-you page
return request.redirect('/thank_you')

Regards

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvc 23
6311
0
bře 15
4068
2
čvn 17
21964
2
bře 15
4236
1
bře 15
3903