xpertbot / craft-wheelform

Craft CMS 4 Form with Database integration
MIT License
66 stars 32 forks source link

How pass url params to field values? #288

Closed maartenheideman closed 1 year ago

maartenheideman commented 1 year ago

Is it possible to set a field value through a url param? For example: domain.com/form/?entryId=10&name=john the form fields entryId and name must get the values set by the url?

xpertbot commented 1 year ago

You can create hidden fields for the values you expect. Then on the template, you get the value from the URL and save it to the field value.

maartenheideman commented 1 year ago

Thanks, I thought maybe there is a function to override values or set them dynamicly. But I'll fixed it by doing this:

{% for field in form.fields %}
   {% if field.type == 'hidden' %}
    <input type="{{field.type}}" value="{{ craft.app.request.queryParam(field.name) ?? '' }}" name="{{field.name}}"/>
   {% endif %}
   {% else %}
    {{ field.render() }}
    {{ wheelformErrors[field.name] is defined ? errorList(wheelformErrors[field.name]) }}
   {% endif %}
{% endfor %}
xpertbot commented 1 year ago

I understand what you were asking. Sure each field is an instance of FieldService here You can use setValue() and set the value of the field and still render it.