Today I had an interesting challenge. I had to create a contact form on the Intranet web site. This web site always has Frontend user logged in. I was going to use standard TYPO3 mailform. Typically such form contains fields for user name and e-mail. When I started to create the form, I immediately realized that it will be stupid to ask for this information if user is already logged it. I should find a way to insert this information automatically.
The obvious solution that come to the mind is to make an extension that will modify the form to include Frontend user data. Yes, it is possible.
But what I like about TYPO3 is that lots of things are possible without PHP programming. And adding Frontend user data to mail form is possible with a simple TypoScript. Here it is:
01: tt_content.mailform = COA_INT
02: tt_content.mailform.20.hiddenFields {
03: name = TEXT
04: name.data = TSFE:fe_user|user|username
05: email = TEXT
06: email.data = TSFE:fe_user|user|email
07: }
(This code assumes that you use CSS styled content, which you definitely should use now!)
Let's start with line 2. It adds hidden fields to the form. The "hiddenFields" property is an array of content objects. Name of the object becomes name of the form field. Value of the object becomes value of the field. In lines 3 to 4 and 5 to 6 I created two fields. I used "data" stdWrap property to fetch Frontend user data. If you do not know what is stdWrap or "data", you can read about it in my article about stdWrap.
How does it look like in HTML? Here is a fragment:
<input type="hidden" name="fromname" value="test01" />
<input type="hidden" name="frommail" value="test@example.com" />
What about line 1? Why is it there?
The answer is simple: you need to make form non-cacheable to avoid caching of the first user who visits this page. You need unique user name and e-mail.
What if user is not logged in?
If user is not logged in, you can use TypoScript conditions to add normal fields to the form.
Extension or TypoScript?
After making this part of code I remembered something. Several times I saw that people make extensions when several lines of TypoScript can do the same work. It reminds me that the first obvious solution is not always the best. There should be no rush with implementation. Careful thinking always produces much better result.
Did I already pronounced this before? Oh, yes. It was mentioned twice: once in my "Background thinking" article and second time during my "Personal productivity" session in TYPO3 user group in the Netherlands in July 2008.
What do you think about it?

Thank a lot for the article
I am often amazed how powerful TYPO3 and TypoScript can be! :)
Did you put that on t3snippets?
Tip: With a condition or a "on page ts record" you can make this just for one page, this way you don't influence all forms.