SID-01157: How to update table cells using a webform?
| Status: |
Answered |
TWiki version: |
5.0.1 |
Perl version: |
5.10.0 |
| Category: |
CategoryEditing |
Server OS: |
Debian 5.0.8, kernel 2.6.26 |
Last update: |
14 years ago |
Hi! I have a table, like the one below, and want to multiply each value in the "Value" column with a number taken from a text field. When I press the "Update" button I want the new (updated) cell values to be saved in the topic.
How can I achieve this? I have tried using a combination of
EditTablePlugin and the
SpreadSheetPlugin but haven't been able to solve it.
Example:
| Nr |
Value |
| 1 |
2300 |
| 2 |
2153 |
| 3 |
3672 |
| 4 |
3644 |
| 5 |
2920 |
Multiply column "Value" with <input type="text" name="var1" size="5" value="3" /><input type="submit" value="Button" class="twikiSubmit" />
New table after update (number=3):
| Nr |
Value |
| 1 |
6900 |
| 2 |
6459 |
| 3 |
11016 |
| 4 |
10932 |
| 5 |
8760 |
--
AlexanderAhman - 2011-04-30
Discussion and Answer
Oops, I see that html code is not supported on this page. It should result in a small web form with one text field and one submit button...
--
AlexanderAhman - 2011-04-30
There is no easy way to update TWiki table cells or HTML table cells programmatically. However, you can easily update
TWikiForms fields. In your example, define a TWiki Form with 5 fields, say Field1, Field2, Field3, Field4, Field5. Attach the form to your page. In your page you can list the table using
VarURLPARAM, such as:
In your HTML form, point the form action to the save script and apply the post method:
<form action="%SCRIPTURL{save}%" method="post">
Then add 5 hidden input fields named after the TWiki form field names. On form submit, use some Javascript to calculate the new values based on the user input, and push those values into the hidden input fields.
--
PeterThoeny - 2011-05-02
Ok, in that case, I guess the only option left is to use a plugin. I have been looking at the source code of your
SpreadSheetPlugin and I think it should not be too difficult to add some sort of "copy down" or "update column" functionality to it. If I do solve this, is it ok to add the new functions to
SpreadSheetPlugin or should I do it in another way?
--
AlexanderAhman - 2011-05-14
I recommend to look into
TWikiForms, they are very flexible and you do not need to create a plugin. See the
How to Create a TWiki Application blog. See related example of updating a TWiki form field,
SID-00250.
The
SpreadSheetPlugin so far only references content, it is not designed to updated content. I am not clear how you would enhance this plugin to do that. You can however use the plugin to do some calculation that is then used to do some action elsewhere, as done in
SID-00250.
--
PeterThoeny - 2011-05-14
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.