forms unleashed

Objective: Insert a $_GET parameter value dynamically into a TypoScript form.

Let's say you want to give your visitors the possibility to send a feedback to some pages (same as we did below in the "Did this document help you"-box). For realizing this completely in TypoScript 2 steps are to consider:

Step 1:
Creating some lines in TypoScript which create an appropriate link. In this case a link with appended parameters which will need in the form later.

Step 2:
Modifying the content.default form in a way that our parameters can be inserted.

step 1: creating a TYPOLINK

  1. # we create a TEXT object named "feedback"
  2. feedback = TEXT
  3.  
  4. # we add a string/value which will be the linked text
  5. feedback.value = give me some feedback to this page
  6.  
  7. # set the link to a specific page ID where the form will reside (in this example PID 33)
  8. feedback.typolink.parameter = 33
  9.  
  10. # of course we need additional parameters to the link
  11. # we pass the $_GET variable value (which has the value "somevalue")
  12. feedback.typolink.additionalParams =&value=somevalue
  13.  

Now we have an object which will create a link like this one (of course you have to put it into a page object to make it appear on the page):

<a href="index.php?id=33&value=somevalue">give me some feedback to this page</a>

Now we are ready for

step 2: creating the form

Go to page 33 (in our example) and create a standard form content element.



  1. # we define a form object
  2. response.form = FORM
  3.  
  4. # now we import the standard mailfrom from the styles.content class
  5. response.form < styles.content.mailform
  6.  
  7. # we override some values (those are not essential for our purpose)
  8. response.form {
  9.   layout = ###LABEL### ###FIELD###<br />
  10.   labelWrap.wrap =|
  11.   fieldWrap.wrap = |<br />
  12.   commentWrap.wrap = |
  13.   radioWrap.wrap = |
  14.   stdWrap.wrap= |
  15.  
  16.   # This is the interesting part:
  17.   # We create a COA object which is applied to the stdWrap. This means, that
  18.   # it will be shown BEFORE the form, so we can use it as headline
  19.   stdWrap.innerWrap.cObject = COA
  20.   stdWrap.innerWrap.cObject {
  21.     10 = TEXT
  22.  
  23.     # We apply our variable (you remember that we named it "value" above)
  24.     # and make it being inserted via insertData.
  25.     # Without insertData {GPvar:value} would be interpreted only as string.
  26.     10.value = <h2>The parameter value is "{GPvar:value}"</h2>
  27.     10.insertData=1
  28.   }
  29.  
  30.   # until this point we have inserted some values, but they are not in the form, yet.
  31.   # So we add our data to the form by the dataArray.
  32.   # Finally we need it as hidden form element:
  33.   dataArray {
  34.     999.type=value=hidden
  35.     999.value= Value passed by $_GET: {GPvar:value}
  36.     999.value.insertData=1
  37.   }
  38. }
  39.  
  40. # Now this is important too: We need to re-import our mailform back into the
  41. # content.default class. The reason is that this class is normally being processed
  42. # earlier, therefore we have to reimport it to make our changes to the default class work
  43. tt_content.mailform.20  < response.form

Voila. Now the $_GET variable will be sent with the form and will appear in the mail, too.

Last update: 19.09.2005

Did this document help you?

Yes: Write us what helped you

Ok, but: Suggest improvements, report inaccuracies etc.

not helpful: Tell us what would have helped