Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Simple form on every product page

Started by Muut Archive 9 years ago · 2 replies · 485 views
9 years ago

I need help with very easy thing. I created form as popup (via Bootstrap modal) and now i need to get it working on every product page. So i inserted code to product template (product.html.twig) and all looks fine. But while studying sending form in doc i can't find how to make it alive. I only found how to create simple form via manually editing markdown header, but no way how to handle form via page templates. Please, can you help me what's the best way to do it in Grav?

My form looks like:

HTML

<div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="customer-name" class="control-label">Name:</label>
                                <input type="text" class="form-control" id="customer-name">
                                <label for="customer-phone" class="control-label">Phone:</label>
                                <input type="text" class="form-control" id="customer-phone">
                                <label for="customer-email" class="control-label">Email:</label>
                                 <input type="text" class="form-control" id="customer-email">
                            </div>
                            <div class="form-group">
                                <label for="message-text" class="control-label">Message:</label>
                                <textarea class="form-control" id="customer-message">Please, send me {{ header.product.name}}.</textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" style="background-color: black">Send</button>
                    </div>
9 years ago

Based on this: https://learn.getgrav.org/forms/forms#displaying-forms-from-twig i created simple file product-form.html.twig with. But it renders just as text.

YAML
forms:
    form:
        name: contact
        fields:
            name: customer-name
            name: customer-email
            name: customer-phone
            name: customer-message
        buttons:
            type: submit
            value: Submit
        process:
        -
            email:
                subject: '[subject] {{ form.value.name|e }}'
                body: 'content' {# {% include ''forms/data.html.twig'' %} #}
        -
            save:
                fileprefix: contact- 
                dateformat: Ymd-His-u
                extension: txt
                body: 'test' {#{% include ''forms/data.txt.twig'' %}#}
        -
            message: 'Thanks'

So i ended with simple PHP form submit, but Twig can't handle it... :(

Any tips how to send own form from Grav?

9 years ago

Meantime i found part of the solution: i created new page, not published, in header all my form id MD and call it in twig.html template with own form. Works now :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1345 9 years ago
Archive · by Muut Archive, 9 years ago
2 933 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2945 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago