Hello @ultrabiker,
Fluent Forms offers various smart codes prepopulate values, please check the screenshot. If the value is fixed, you can directly put the value as well; kindly refer to this screeenshot. Let us know if this helps.
Thank you
Thank you @amimulihsanmahdi,
I know of the smart codes, and yes I understood you can prepopulate the field manually.
Nevertheless, this is not really useful for me in this case.
This Is what I try to do:
Users can download an ebook from my website. For each ebook I would like to create only one form. Than with Conditional Logics I determine what Email Notification is send to the User with the correct email and link to the correct ebook download.
This could populate the hidden field with {get.ebook} but I need a clean URL and would like to populate the hidden field in an other way in the wordpress page itself.
Something like [fluentform id=”11″ param=somevalue] would be awesome but I guess that is not available. Or can it be somehow created in php so it wil be able to do that?
Hello again,
Unfortunately, using shorcodes like [fluentform id=”11″ param=somevalue] is not possible as Fluent Forms does not offer any such shortcodes. This might be possible using custom shortcode but this will require custom coding which falls beyond our support scope.
Thank you
Thank you @amimulihsanmahdi
I have created a function that will do what I would like.
For others to use as they would see fit.
// Create a custom shortcode to handle dynamic form embedding
// USE: [dynamic_fluentform id="11" ebook="my-ebook-slug"]
function dynamic_fluentform_shortcode($atts) {
// Extract attributes passed to the shortcode
$atts = shortcode_atts(array(
'id' => '', // FluentForm ID
'ebook' => '' // The dynamic eBook value or any custom param
), $atts, 'dynamic_fluentform');
// Sanitize values (always sanitize user inputs/attributes)
$form_id = intval($atts['id']);
$ebook_id = sanitize_text_field($atts['ebook']);
// Generate the FluentForm shortcode with dynamic hidden field value
$output = do_shortcode('[fluentform id="' . $form_id . '"]');
// Inject the hidden field value into the form using JS if necessary
$output .= "<script>
document.addEventListener('DOMContentLoaded', function() {
var ebookField = document.querySelector('input[name=\"ebook_id\"]');
if(ebookField) {
ebookField.value = '" . esc_js($ebook_id) . "';
}
});
</script>";
return $output;
}
// Register the custom shortcode
add_shortcode('dynamic_fluentform', 'dynamic_fluentform_shortcode');