SID-00054: Recording Form Values when they change
| Status: |
Answered |
TWiki version: |
|
Perl version: |
|
| Category: |
CategoryForms |
Server OS: |
|
Last update: |
16 years ago |
I have forms and I want to record the previous value of an variable when it is changed by the user. My main thought was to use the
CommentPlugin form and post to the comment box the previous values but I seem to post live wiki variables rather than the static value. Ideally, I would like to post the static values to a separate log topic.
The code I have so far is below:
%TMPL:DEF{"ValueOnly"}% %Item% %TMPL:END%
%TMPL:DEF{PROMPT:ExampleFormFieldCommentBoxChanger}%%TMPL:P{promptbox}%Change DCA status to:
<select %DISABLED% name="DcaType">
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 1'" then="selected='selected'"}%>DCA 1</option>
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 2'" then="selected='selected'"}%>DCA 2</option>
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 3'" then="selected='selected'"}%>DCA 3</option>
</select> %TMPL:END%
%TMPL:DEF{OUTPUT:ExampleFormFieldCommentBoxChanger}%%TMPL:P{OUTPUT:threadmode}% %BR% DCA changed to:
%TMPL:P{"ValueOnly" Item="%META{'formfield' name='DcaType'}%"}% %TMPL:END%
So my plan was to the ValueOnly Template definition to convert the wiki variable %META...% and return its value so I could post the value to the topic then there is a fixed record of what the value was. Ideally I would like to capture the value before it was changed but that would come after I got this working!!
Comment Plugin Version: 12750 (04 Feb 2007)
Many thanks,
--
NeilGood - 24 Jan 2009
Discussion and Answer
I think I have an answer - see code below:
%TMPL:DEF{StoreValueDcaType}%
<input type="hidden" name="ValueDcaType" value="%FORMFIELD{DcaType}%" />
%TMPL:END%
%TMPL:DEF{PROMPT:ExampleFormFieldCommentBoxChanger}%
%TMPL:P{StoreValueDcaType}%
%TMPL:P{promptbox}%
Change DCA status to: <select %DISABLED% name="DcaType">
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 1'" then="selected='selected'"}%>DCA 1</option>
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 2'" then="selected='selected'"}%>DCA 2</option>
<option %IF{"'%FORMFIELD{DcaType}%'='DCA 3'" then="selected='selected'"}%>DCA 3</option>
</select>
%TMPL:END%
%TMPL:DEF{OUTPUT:ExampleFormFieldCommentBoxChanger}%%TMPL:P{OUTPUT:threadmode}%
* Previous DcaType: %URLPARAM{ValueDcaType}%
%TMPL:END%
The answer came from the Return Form, the short bit of template which sets the Rediectto to the value of the calling web....combined that with the 1 in the Output statement and that seemed to work....
Next challenge is to post the static values to a log file/topic as well to track the changes in a simple change log........
I am going to cheekily set the field to answered!
--
NeilGood - 28 Jan 2009
Thanks Neil for reporting back so that other community members can learn!
--
PeterThoeny - 30 Jan 2009
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.