The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Front-End Entry Duplication, Passing Only One Value to the URL
UPDATE: It just occured to me that you can use the built-in Formidable shortcode to do almost all of this, without the custom function:
Although, if I'm not mistaken, you cannot use this shortcode to format a Date field. I could be wrong, but if not, then the custom function below will handle that for you. Now to the original post:
So the long way to duplicate an entry on the front-end is to create a link to your form page, and pass the info from each field into a series querystring params, and then add a [get param=whatever] to all your fields. This is fine for most purposes. But it can be problematic (1) if you want to pass sensitive user information and don't want it being saved from the URL query string into people's browser histories, and (2) if the form is so big, eventually the browser won't accept any more info to your query string (that happened to me).
So instead of doing that, here's the easy way to do it. You only need to pass one parameter to your url. The entry id of the entry you want to duplicate. Add this custom shortcode to your theme's functions.php or to your own plugin:
add_shortcode('entry_data', 'myprefix_entry_data');
function myprefix_entry_data($atts){
extract(shortcode_atts(array('field' => '', 'format' => '', 'show' => '', 'user' => 0), $atts));
$output = null;
if (isset($_REQUEST['duplicate'])):
$id = $_GET['duplicate'];
if (!$user and !$show)
$output = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $field, 'entry_id' => $id));
elseif ($user and !$show)
$output = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $field, 'user_id' => $id));
elseif ($show and !$user)
$output = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $field, 'show' => $show, 'entry_id' => $id));
elseif ($show and $user)
$output = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $field, 'show' => $show, 'user_id' => $id));
if ($format)
$output = date($format, strtotime($output));
endif;
return $output;
}
So having added that shortcode to your functions.php or personal plugin, next you have to pass the entry id of your form entry to the url. So in your View, the link would look like:
<a href="www.myurl.com/myformpage/?duplicate=[id]">Duplicate</a>
If you want to use something other than "duplicate" for your param, change these two lines in your shortcode function:
if (isset($_REQUEST['duplicate'])): $id = $_GET['duplicate'];
replacing 'duplicate' with whatever you want.
Now you just use the shortcode in each field on the form you want to duplicate, like so:
[entry_data field=125]
It will automatically look for the param "duplicate" (or whatever you've set it to in the shortcode function), and will use that entry id to find the value for field 125. Here is some more usage of the shortcode for you:
[entry_data field=125 user=1]
Adding user=1 to your shortcode will tell it to read the numeric value in the querystring as a user_id rather than an entry_id. So if you wanted to do that, you would change your html link to put the user_id (e.g., [100 show=id]) rather than the entry_id. Otherwise, just leave the "user" attribute out of the shortcode. That's all it does.
[entry_data field=125 show=id]
Use this if you want to output the id, instead of the text value.
[entry_data field=125 show=value]
Use this if you want to output the saved value rather than the displayed value in a checkbox, radio, or dropdown field that is set to use separate values.
[entry_data field=125 format="Y-m-d"]
Use the format attribute in this shortcode just like you would in any Date field in a View.
Note that with date fields, you'll need to remove the standard 10 character limit in order to fit this shortcode in for it to grab the default value.
You can also use multiple shortcodes in a single field. So for instance, if I want to grab info from one form, and import it into another, and in the other one, I want to put the whole address in one field (rather than the standard five fields that I use), I would do:
[entry_data field=902] [entry_data field=903] [entry_data field=904] [entry_data field=905] [entry_data field=906]
all in one field on the second form.
You can also change the shortcode name. Just change "entry_data" to whatever you want. You might want to make it shorter, for instance.
add_shortcode('dupit' 'myprefix_entry_data');
So anyway, that's how you can duplicate an entire form entry on the front-end without passing all the sensitive information over the url. All it requires is passing the single entry id of the entry you want to duplicate.
If you know what you're doing, this shortcode function can be expanded to suit your purposes. This is a lightweight version of some of the functions that I use to get the job done.
March 10, 2014 at 4:21 am
Thank you, I was about to ask something similar.
With reference to this https://formidablepro.com/knowledgebase/setting-and-getting-url-parameters/ , was gonna ask if there's anything that can pass multiple values from custom display to form.
March 10, 2014 at 8:22 am
Actually, please take a look at the "shortcode enhancements" section here:
https://formidableforms.com/formidable-1-07-05/
March 10, 2014 at 8:29 am
Yes, thanks. You'll notice I updated the post (about twenty minutes or so after posting it) pointing out that you can do most of this with the frm-field-value shortcode. With the one exception I think of choosing the format of date fields. Is that an option with the frm-field-value shortcode?
March 10, 2014 at 10:50 am
Yep, you're right. We'll look into adding a format option to that shortcode.
March 11, 2014 at 11:17 pm
That would be terrific! Thanks much, Steph.
Discussion closed.