Cloning a Record

Often, you want to copy a record and change one thing, like a date, or make some other minor modification.

numero = 138
interpreted = N
texte = I have come up with a very simple technique. Alongside the link to EDIT a record, I make a link to CLONE a record, adding clone=t to the editing link. Then in the editing code, there are only 2 simple alterations. In the form itself, use [hideif [clone]=t] to hide the hidden variable for the record ID, and in the replace context, add &append=t&autonumber=ID (or whatever your record ID field is called). When you search for the record to populate your field, it finds [ID]. But when you submit the form, this variable is not sent and only the raw code, [ID] displays for the replace, so the record is not found. Hence, a new record is created with a new ID. LINK
<a href="youreditpage.dna?edit=t&ID=[ID]">EDIT</a> | <a href="youreditpage.dna?edit=t&ID=[ID]&clone=t">COPY</a>
FORM element
[hideif [clone]=t] <input type=hidden name=ID value=[ID]>[/hideif]
WRITE to the DB
[replace db=yourdatabase.db&eqIDdatarq=[ID]&append=T&autonumber=ID]....[/replace]
NOTES

Make sure your editing form contains all the fields; often a new form has additional fixed fields that are set only on a new record. So you may have to add these in hidden form elements.

If you want to make sure a particular field is replaced with new info, do something like: <input type=text name=mtgdate value="[hideif [clone]=t][mtgdate][/hideif]"> You can also put this at the top of the form: [showif [clone]=t]This form will create a New Copy of an existing record[/showif] to reassure yourself that you aren't editing away an existing record. You can change the text on the submit button to Clone in the same way with showif/hideif.

I have come up with a very simple technique. Alongside the link to EDIT a record, I make a link to CLONE a record, adding clone=t to the editing link. Then in the editing code, there are only 2 simple alterations. In the form itself, use [hideif [clone]=t] to hide the hidden variable for the record ID, and in the replace context, add &append=t&autonumber=ID (or whatever your record ID field is called). When you search for the record to populate your field, it finds [ID]. But when you submit the form, this variable is not sent and only the raw code, [ID] displays for the replace, so the record is not found. Hence, a new record is created with a new ID.

LINK
<a href="youreditpage.dna?edit=t&ID=[ID]">EDIT</a> | <a href="youreditpage.dna?edit=t&ID=[ID]&clone=t">COPY</a>


FORM element
[hideif [clone]=t] <input type=hidden name=ID value=[ID]>[/hideif]


WRITE to the DB
[replace db=yourdatabase.db&eqIDdatarq=[ID]&append=T&autonumber=ID]....[/replace]


NOTES

Make sure your editing form contains all the fields; often a new form has additional fixed fields that are set only on a new record. So you may have to add these in hidden form elements.



If you want to make sure a particular field is replaced with new info, do something like:
<input type=text name=mtgdate value="[hideif [clone]=t][mtgdate][/hideif]">

You can also put this at the top of the form:

[showif [clone]=t]This form will create a New Copy of an existing record[/showif]

to reassure yourself that you aren't editing away an existing record.

You can change the text on the submit button to Clone in the same way with showif/hideif.



Terry Wilson

DOWNLOAD WEBDNA NOW!

Top Articles:

WebDNA Modules

A list of the currently available modules...

AWS Raw WebDNA LAMP-Plus WebServer

Amazon Web Services (AWS) README for Machine Image ID...

WebDNA Libraries

A list of available libraries for WebDNA...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

Tips and Tricks

A list of user-submitted tips ...

Download WebDNA Applications

WebDNA applications...

Related Readings:

How to create a RSS feed

How to create a RSS feed from yourdatabase on formation...

How to setup CODA to work with WebDNA?

This page will show graphically how to setup CODA as a WebDNA partner :-)...

Do you hate updating the copyright notice at the bottom of all your pages?

It's January 1st and you have to update the copyright notice at the bottom of all your websites...

Redefining [date] & [time] to match your time zone

Your server is not always in the same time zone as your web site...

Write Once Use Many

Reuse the same code over and over again on your site with the [include] context...

How to keep the text variable after a function has finished

By default...