Skip to content

Instantly share code, notes, and snippets.

View aimahdi's full-sized avatar
💭
Working on something bigger

Amimul Ihsan aimahdi

💭
Working on something bigger
View GitHub Profile
@aimahdi
aimahdi / Conversational forms custom js.js
Created September 9, 2023 09:41
Use custom JS on conversational forms
add_action('fluentform/conversational_frame_footer', function() {
printf("<script type='text/javascript' id='%s-js-extra'>\n", esc_attr($handle));
$data = "
let name = document.querySelector(\"[name=\'input_text\']\");
name.value = \"Ibrahim Mahdi\";
console.log(name.value)";
echo "$data\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $data is hardcoded localized data and escaped before being passed in.
add_filter('fluentform/editor_countries', function ($country_names) {
foreach ($country_names as $key => $value) {
if (preg_match("/\([^)]+\)/", $value)) {
$replacedValWithSpaceInBetween = preg_replace("/\s+\([^)]+\)/", "", $value);
$country_names[$replacedValWithSpaceInBetween] = $replacedValWithSpaceInBetween;
} else {
$country_names[$value] = $value;
}
unset($country_names[$key]);
}
add_filter('fluentform/response_render_tabular_grid', function ($response, $field, $form_id, $isHtml = false) {
$field['raw']['settings']['grid_columns'] = ['Ashik'=>'Ashik', 'Ruman'=>'Ruman'];
$field['raw']['settings']['grid_rows'] = ['Ibrahim'=>'Ibrahim', 'Nadim'=>'Nadim', 'Tahmid'=>'Tahmid', 'Mahdi'=>'Mahdi'];
return \FluentForm\App\Modules\Form\FormDataParser::formatTabularGridFieldValue($response, $field, $form_id, $isHtml);
}, 9, 4);
add_filter('fluentform/validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {
// You may change the following 3 lines
$targetFormId = 101; //change the form id with your own.
$errorMessage = 'Looks like email is not correct, please use a valid email'; // You may change/modify the meessage
$apiKey = 'lYlSwj3Uxt5iGecFTHYdqKC4xBQYaClfsss'; //reoon API key, you should use your own api key
if ($form->id != $targetFormId) {
return $default;
}
add_action( 'woocommerce_review_order_before_submit', 'custom_content_before_order_submit_button' );
function custom_content_before_order_submit_button() {
(new \FluentCampaign\App\Services\Integrations\WooCommerce\WooInit())->addSubscribeBox();
}
@aimahdi
aimahdi / wordpress-fluentform-javascript-triggers.js
Created September 11, 2024 11:52 — forked from jennlee20/wordpress-fluentform-javascript-triggers.js
wordpress-fluentform-javascript-triggers.js
$form.on('ff_to_next_page', function(activeStep, form) {
console.log(activeStep);
// You can run your own JS on step change
});
$form.on('ff_to_prev_page', function(activeStep, form) {
console.log(activeStep);
// You can run your own JS on step change
});
private function pushScripts($data, $form)
{
add_action('wp_footer', function () use ($data, $form) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
if (typeof $.fn.fileupload !== 'undefined') {
delete $.fn.fileupload;
console.log("jQuery.fn.fileupload function removed");
}
add_filter('fluentform/rendering_field_data_custom_html', function ($data, $form)
{
if($form->id != 50) { //change the form id with your own form id
return $data;
}
global $post;
$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); // Get the thumbnail ID
window.onload = function(){
//First Group
var select = document.getElementById("ff_136_dropdown"); //change the dropdown id
var optgroup = document.createElement("optgroup");
optgroup.label = "Foyla Title";
var option1 = select.querySelector('option[value="Option 1"]'); //change the value of the option
var option2 = select.querySelector('option[value="Option 2"]'); //change the value of the option
add_filter('fluentform/shortcode_defaults', function($data, $atts) {
$formId = \FluentForm\Framework\Helpers\ArrayHelper::get($atts, 'id');
if ($formId) {
$form = \FluentForm\App\Models\Form::find($formId);
// check form and do your work and return null;
return null;
}
return $data;