Is it possible for Chronoform to retrieve a field data from a row in the database, add 1 to it and save it back to the same row?
We are creating a form where a student submits work - data is inserted into the database. When they resubmit their work, the data is updated. We want to show how many resubmissions they have done (ie, how many times the data row, has been updated) without having to create a new row of data each time they resubmit.
We are creating a form where a student submits work - data is inserted into the database. When they resubmit their work, the data is updated. We want to show how many resubmissions they have done (ie, how many times the data row, has been updated) without having to create a new row of data each time they resubmit.
Use read_data first, set to first found:
In a PHP block within the "record found":
In a PHP block within the "record found":
return $this->get("read_data#.model.field") + 1;Then in your save data action, for the incrementing field, in the "override on update" bit,
field:{var:php_block_name}
Bonus: to make this work for the first submission as well, use
Also: editing the previous post.
field:{var:php_block_name/1}
Also: editing the previous post.
Many thanks healyhatman.
On a similar note, how can we get the "first matching record" to select the newest row? It seems to be selecting the first row it finds (ie smallest aid in the table) which happens to be the oldest.
Edit: It's okay, solved that. We just have to put the relevant field under 'Order fields' in the read_data function.
On a similar note, how can we get the "first matching record" to select the newest row? It seems to be selecting the first row it finds (ie smallest aid in the table) which happens to be the oldest.
Edit: It's okay, solved that. We just have to put the relevant field under 'Order fields' in the read_data function.
This topic is locked and no more replies can be posted.