This topic is locked

Copy field contents to clipboard

9/24/2021 4:23:53 AM
PHPRunner General questions
S
SteveDickson author

I noticed a post from over four years ago related to add/edit pages.

Q: I want to create a button that will copy the data entered in to the field named "FirstName" before the record is added or inserted.
A: Yes, this can be done. Insert a button using 'Insert button' function in Visual Editor and put the following code to Client Before event:

$("#value_FirstName_1").select();

document.execCommand("copy");

$("#value_FirstName_1").blur();

Question is, can anyone think of a way to create something like this on a view page? I want people to share a URL such as
domainname.com/this_project/go_here.php?editid=1&code=abcxzy
The "code" is designed to stop anyone just 'flicking' through the records and is randomly generated before the record is saved. I can make a field that combines it all together, but would love and easy way for them user to just view the page and click to copy the contents of the link for the page it's directing to.

mbintex 9/24/2021

This blog entry from Xlinesoft discusses something very similar:

https://xlinesoft.com/blog/2021/09/09/providing-access-to-web-application-via-unique-link/

S
SteveDickson author 9/24/2021

Thanks for that but I've got the field organised. I would just like any easy way for someone to "Copy" the link so they can post it elsewhere (website, facebook, etc).

A
acpan 9/25/2021

Not sure If I understand correctly, if you want to concatenate the values of the fields on the view page and copy to clipboard, so that you can paste it else where, here's what you can do:

  1. Insert a button on the view page, and name it eg. "Copy url"


  2. In Client Before event of the button, enter the codes as follows:

    // Get the selector ID. Notice that the selector ID is normally **view1_**fieldname
    var id = $('#view1_id');
    var code = $('#view1_code');
    // form the url, use id.val() or id.html() depending on your requirement
    var url = "https://domainname.com/this_project/go_here.php?edit1=" + id.html()+"&code="+code.html();
    //transfer to clipboard
    navigator.clipboard.writeText(url);
    // alert to double check
    alert("Copied URL: " + url);

  3. Try paste anywere to verify that the pasted values are the copied values.



Note: as you said, the code is generated when record is saved, you can use set proxy value to transfer the code value from PHP Before display event to JavaScript Onload event of view page, or show the code directly from the view page to implement the above.