5

I'm trying to retrieve custom fields value after submitting a form. Trying to access the custom fields through the message element after the form is submitted always throws an error that the custom fields variable does not exist.

Example that works:

<label for="fromName">Name:*</label>
<input id="fromName" type="text" name="fromName" value="{% if message is defined %}{{ message.fromName }}{% endif %}">`

Example that doesn't work (custom fields):

<label for="fromCompany">Company:</label>
<input id="fromCompany" type="text" name="message[fromCompany]" value="{% if message is defined %}{{ message.fromCompany }}{% endif %}">

Is it possible to retrieve custom field values after submitting the form?

  • Any update this this? I'd like to grab the current value, and also any error message associated with the custom field. – user1085 Dec 9 '14 at 17:41
  • Has there been any development on this? Struggling to access additional fields in submitted forms (eg on return from error). – Cole Henley Sep 17 '15 at 9:55
3

I just came across this question, for the sake of up to date info for others, it is now possible to do this with the latest release(1.7) of the ContactForm plugin from Pixel & Tonic: https://github.com/pixelandtonic/ContactForm

<input id="fromCompany" type="text" name="message[fromCompany]" value="{% if message is defined %}{{ message.messageFields.['fromCompany'] }}{% endif %}">
| improve this answer | |
3

In Craft 2.5 with Contact Form 1.4 I'm receiving the same error when using:

{% if message is defined %}{{ message.contactTel }}{% endif %}

I've gotten around this by using the Craft Request method getPost which can return a post value from an array. In the case of the original question, the following should work:

<label for="fromCompany">Company:</label>
<input id="fromCompany" type="text" name="message[fromCompany]" value="{% if message is defined %}{{ craft.request.getPost('message.fromCompany') }}{% endif %}">
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.