architecture – Database Design for Form Builder

Hi guys I’m trying to create Form builder in my app for different Events that have happened and publish them, so the users can fill them out.

Little About Logic:

Forms are created per different Event that has happened, and then users can popuplate and view them

As for the database I’m using Postgres.

Here is how my current models look:

Form model:

form
-----
  id (PK)
  name
  user_id (FK to users.id)

Form Element

form_element
-------------
  id (PK)
  form_id (FK to form.id)
  element_type_id (FK to element_type.id)

Element Type (could be text_field, radio, dropdown)

element_types
-------------
  id (PK)
  name

Element Values (Stores Values inputed by User)

Form Element value
===============
    id (PK)
    element_id (FK to form_elements.id)
    user_id (FK to user.id)
    value

The form is populated with form_elements that reference the forms. And has a relationship 1 to many (one form has many fields). element_types is used so they know which type they are. element_types will store a list of different elements a form can have. Types could be: “text_field”, “drop_down_list”, “radio_buttons”, “checkbox”.

Now I have few questions about my Database Design ?

  1. Form Element model and Element Type model should have 1 to 1 relationship ?
  2. How should I create for example type Dropdown where would I store additional fields for Dropdown options in a new field, in a new Table, how would I design that ?
  3. Element Values table should be Many to Many, should I have to store user_id per Field valoue or could i have somehow bind it to Form ?

Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin

I have a custom plugin with the following code

add_action( 'init', 'my_script_enqueuer' );

function my_script_enqueuer() {
   wp_register_script( "gift_card_redeem", WP_PLUGIN_URL.'/plugin-folder/gift_card_redeem.js', array('jquery') );
   wp_localize_script( 'gift_card_redeem', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));        

   wp_enqueue_script( 'jquery' );
   wp_enqueue_script( 'gift_card_redeem' );

}

add_action("wp_ajax_gift_card_redeem", "gift_card_redeem");

function gift_card_redeem(){

  if(!empty($_SERVER('HTTP_X_REQUESTED_WITH')) && strtolower($_SERVER('HTTP_X_REQUESTED_WITH')) == 'xmlhttprequest') {
    error_log("test !empty");
    $result('type') = "success";
    $result = json_encode($result);
    echo $result;
  }
  else {
    error_log("test else");
      header("Location: ".$_SERVER("HTTP_REFERER"));
  }

  die();
}

and a js file in the plugin called gift_card_redeem.js

jQuery(document).ready(function () {
  jQuery(".redeem_gift_card").click(function (e) {
    e.preventDefault();

    jQuery.ajax({
      type: "post",
      dataType: "json",
      url: myAjax.ajaxurl,
      data: { action: "redeem_gift_card" },
      success: function (response) {
        if (response.type == "success") {
          jQuery("#test").html(response);
        } else {
          alert("something broke");
        }
      },
    });
  });
});

and my php and html on the form-checkout page is as follows

<?php
    $link = admin_url('admin-ajax.php?action=gift_card_redeem');
        echo '<a class="redeem_gift_card" href="' . $link . '" >test</a>';
    ?> 

    <h1 id="test">Test</h1>

I am getting a 400 bad request error for admin-ajax.php and I am not quite sure why. Any help would be greatly appreciated.

Thanks

entities – Views entity reference depending on other field in contact form

I have almost the same problem than Peter, here: Entity reference view depending on other field

I have a contact form with two fields: brand and model. Brand is a taxonomy field and Model en entity reference view field. Model field (autocomplete) should be dependent on brand value: nothing if brand is not selected or only products with the brand field chosen.

I think @Francis Yaconiello gave the right answer but I don’t understand the relations and contextual filter in his view. If you see this, Francis, can you help me?

Anyone?

Thank you

customization – How do I add a dropdown menu to a form?

I am trying to create a dropdown list that will insert numbers based on numbers already used for that group of numbers. Example: dropdown will include numbers such as (100, 200, 300, etc) and I want to append a group of numbers to them like this (100-0001). The appended numbers need to be sequential starting at 0001 but they need to be sequential according to which prefix is used. Also, I need to insert this dropdown on a form in WordPress.

Get the form to add a term to a vocabulary programmatically

I am working on Drupal 8.9.6.

I am trying to retrieve the form to add a term to a vocabulary programmatically. I know how to do it for a content type:

    $values = array('type' => $content_type);

    $node = Drupal::entityTypeManager()
      ->getStorage('node')
      ->create($values);

    $form = Drupal::entityTypeManager()
      ->getFormObject('node', 'default')
      ->setEntity($node);
    $modal_form =  Drupal::formBuilder()->getForm($form);

Nevertheless, I am not able to do the same for the form of adding a term to a vocabulary. Any hint would be more than welcome.

Thanks!

c# – Xamarin Forms with tabbed pages having data form entry page in each tabbed page

I’m new to Xamarin. I’ve a Xamarin forrms app with Tabbed Pages and it has 3 tabs with each tab having a data entry form and all data entry forms should be passed to a webapi DTO entity class. How do i collect all the data from the 3 pages in the 3 tabs and post the data when i click the submit button on the 3rd tab. What is the best way to implement this? My codes are below

DTO FamilyTreeMaster in Models

                using System;
                    using System.Collections.Generic;
                    using System.Text;

                    namespace FamilyTreeApp.Models
                    {
                public class DTOFamilyTreeMaster
                {
                    public string Title { get; set; }
                    public string FirstName { get; set; }
                    public string LastName { get; set; }
                    public Nullable<int> Age { get; set; }
                    public string Profession { get; set; }
                    public string FatherFirstName { get; set; }
                    public string FatherLastName { get; set; }
                    public string MotherFirstName { get; set; }
                    public string MotherLastName { get; set; }
                    public string Address1 { get; set; }
                    public string Address2 { get; set; }
                    public string City { get; set; }
                    public string State { get; set; }
                    public string Zip { get; set; }
                    public string Country { get; set; }
                    public string Phone { get; set; }
                    public string Spouse1_FirstName { get; set; }
                    public string Spouse1_LastName { get; set; }
                    public string Spouse2_FirstName { get; set; }
                    public string Spouse2_LastName { get; set; }
                    public string Spouse3_FirstName { get; set; }
                    public string Spouse3_LastName { get; set; }
                    public string Spouse4_FirstName { get; set; }
                    public string Spouse4_LastName { get; set; }
                    public string Spouse5_FirstName { get; set; }
                    public string Spouse5_LastName { get; set; }
                    public string Son1_FirstName { get; set; }
                    public string Son1_LastName { get; set; }
                    public string Son2_FirstName { get; set; }
                    public string Son2_LastName { get; set; }
                    public string Son3_FirstName { get; set; }
                    public string Son3_LastName { get; set; }
                    public string Son4_FirstName { get; set; }
                    public string Son4_LastName { get; set; }
                    public string Son5_FirstName { get; set; }
                    public string Son5_LastName { get; set; }
                    public string Son6_FirstName { get; set; }
                    public string Son6_LastName { get; set; }
                    public string Son7_FirstName { get; set; }
                    public string Son7_LastName { get; set; }
                    public string Son8_FirstName { get; set; }
                    public string Son8_LastName { get; set; }
                    public string Son9_FirstName { get; set; }
                    public string Son9_LastName { get; set; }
                    public string Son10_FirstName { get; set; }
                    public string Son10_LastName { get; set; }
                    public string Daughter1_FirstName { get; set; }
                    public string Daughter1_LastName { get; set; }
                    public string Daughter2_FirstName { get; set; }
                    public string Daughter2_LastName { get; set; }
                    public string Daughter3_FirstName { get; set; }
                    public string Daughter3_LastName { get; set; }
                    public string Daughter4_FirstName { get; set; }
                    public string Daughter4_LastName { get; set; }
                    public string Daughter5_FirstName { get; set; }
                    public string Daughter5_LastName { get; set; }
                    public string Daughter6_FirstName { get; set; }
                    public string Daughter6_LastName { get; set; }
                    public string Daughter7_FirstName { get; set; }
                    public string Daughter7_LastName { get; set; }
                    public string Daughter8_FirstName { get; set; }
                    public string Daughter8_LastName { get; set; }
                    public string Daughter9_FirstName { get; set; }
                    public string Daughter9_LastName { get; set; }
                    public string Daughter10_FirstName { get; set; }
                    public string Daughter10_LastName { get; set; }
                    public Nullable<int> MyPosition { get; set; }
                    public Nullable<int> MyParentPosition { get; set; }
                }
            }

Tabbed pages in views

UserInfoTabbedPage

                <?xml version="1.0" encoding="utf-8" ?>
            <TabbedPage Visual="Material" 
                            xmlns="http://xamarin.com/schemas/2014/forms"
                                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:FamilyTreeApp.Pages"
                                    x:Class="FamilyTreeApp.Pages.UserInfoTabbedPage">
                <local:UserTabbedPage  Title ="User" 
                                                 Icon ="user.png"/>
                <local:UserSpousePage Title ="Family" 
                                                 Icon ="sharp_group_add_black_18.png"/>
                <local:UserChildrenTabbedPage class="material-icons"  Title ="User" 
                                                 Icon ="user.png"/>

            </TabbedPage>   




   

UserTabbedPage

                    <?xml version="1.0" encoding="utf-8" ?>
                <ContentPage Visual="Material"
                                xmlns="http://xamarin.com/schemas/2014/forms"
                                         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                         x:Class="FamilyTreeApp.Pages.UserTabbedPage">
                    <TableView Intent="Form">
                        <TableRoot>
                            <TableSection Title="Basic">
                                <EntryCell Placeholder="Title" Text="{Binding Title}"></EntryCell>
                                <EntryCell Placeholder="First Name" Text="{Binding FirstName}"></EntryCell>
                                <EntryCell Placeholder="Last Name" Text="{Binding LastName}"></EntryCell>
                                <EntryCell Placeholder="Nick Name" Text="{Binding NickName}"></EntryCell>
                                <EntryCell Placeholder="Age" Text="{Binding Age}"></EntryCell>
                                <EntryCell Placeholder="Profession" Text="{Binding Profession}"></EntryCell>
                            </TableSection>
                            <TableSection Title="Contact">
                                <EntryCell Placeholder="Address 1" Text="{Binding Address1}"></EntryCell>
                                <EntryCell Placeholder="Address 2" Text="{Binding Address2}"></EntryCell>
                                <EntryCell Placeholder="City" Text="{Binding City}"></EntryCell>
                                <EntryCell Placeholder="State" Text="{Binding State}"></EntryCell>
                                <EntryCell Placeholder="Zip" Text="{Binding Zip}" Keyboard="Numeric"></EntryCell>
                                <EntryCell Placeholder="Country" Text="{Binding Country}"></EntryCell>
                                <EntryCell Placeholder="Phone" Text="{Binding Phone}" Keyboard="Numeric"></EntryCell>

                            </TableSection>
                        </TableRoot>
                    </TableView>

                </ContentPage>

     

UserSpousePage

                    <?xml version="1.0" encoding="utf-8" ?>
                <ContentPage Visual="Material"
                            xmlns="http://xamarin.com/schemas/2014/forms"
                                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                     x:Class="FamilyTreeApp.Pages.UserSpousePage"
                                     xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
                                     >
                <TableView Intent="Form">
                    <TableRoot>
                        <TableSection Title="Parents">
                            <EntryCell  Placeholder="Father First Name" Text="{Binding FatherFirstName}"></EntryCell>
                            <EntryCell Placeholder="Father Last Name" Text="{Binding FatherLastName}"></EntryCell>
                            <EntryCell Placeholder="Mother First Name" Text="{Binding MotherFirstName}"></EntryCell>
                            <EntryCell Placeholder="Mother Last Name" Text="{Binding MotherLastName}"></EntryCell>

                        </TableSection>

                        <TableSection x:Name="Spouses" Title="Spouse(s)">
                            <ViewCell>
                                <StackLayout>
                                    <Grid>

                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20"/>
                                            <ColumnDefinition Width="2*"/>
                                        </Grid.ColumnDefinitions>

                                        <Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" 
                                                                           Text="{Binding Source={x:Reference stepper},Path=Value}"/>

                                        <Stepper Grid.Row="0" Grid.Column="1" x:Name="stepper" Increment="1" Maximum="5" Minimum="1" >
                                        </Stepper>
                                        <ic:CircleImage  Grid.Row="0" Grid.Column="2"  Source="sharp_group_add_black_18.png">
                                            <Image.GestureRecognizers>
                                                <TapGestureRecognizer Tapped="OnStepperValueChanged" />
                                            </Image.GestureRecognizers>

                                        </ic:CircleImage>

                                    </Grid>

                                </StackLayout>

                            </ViewCell>
                        </TableSection>
                    </TableRoot>
                </TableView>

                </ContentPage>

UserSpousePage.xaml.cs

            using Xamarin.Forms;
                using Xamarin.Forms.Xaml;

                namespace FamilyTreeApp.Pages
                {
                    (XamlCompilation(XamlCompilationOptions.Compile))
                    public partial class UserSpousePage : ContentPage
                    {
                        public int countSpouses = 1;

                        public UserSpousePage()
                        {

                            InitializeComponent();
                            //CreateEntryCells(10);

                        }

                        private void CreateEntryCells(int numCell, string textToBeCreated)
                        {
                            for (int i = countSpouses; i<= numCell; i++)
                            {
                                EntryCell entInput = new EntryCell
                                {
                                    Placeholder = textToBeCreated + countSpouses
                                };

                                string txt = "{Binding" + textToBeCreated + countSpouses + "_FirstName}";
                                //string txtLastName = "{Binding" + textToBeCreated + countSpouses + "_LastName}";

                                entInput.SetBinding(EntryCell.TextProperty, txt);

                                Spouses.Add(entInput);
                                ++countSpouses;

                            }

                                  }

   
                        private void OnStepperValueChanged(object sender, System.EventArgs e)
                        {
                            CreateEntryCells(int.Parse(stepper.Value.ToString()),"Spouse Full Name");

                        }
                    }
                }

UserChildrenTabbedPage

                    <?xml version="1.0" encoding="utf-8" ?>
                <ContentPage Visual="Material" xmlns="http://xamarin.com/schemas/2014/forms"
                                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
                                 x:Class="FamilyTreeApp.Pages.UserChildrenTabbedPage">
                    <AbsoluteLayout HorizontalOptions="FillAndExpand"  
                                        VerticalOptions="FillAndExpand">

                <TableView Intent="Form">
                    <TableRoot>

                        <TableSection x:Name="Sons" Title="Son(s)">
                            <ViewCell>
                                <StackLayout>
                                    <Grid>

                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20"/>
                                            <ColumnDefinition Width="2*"/>
                                        </Grid.ColumnDefinitions>

                                        <Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperSon},Path=Value}"/>

                                        <Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperSon" Increment="1" Maximum="10" Minimum="1" >
                                        </Stepper>
                                        <ic:CircleImage  Grid.Row="0" Grid.Column="2"  Source="sharp_group_add_black_18.png">
                                            <Image.GestureRecognizers>
                                                <TapGestureRecognizer Tapped="OnstepperSonValueChanged" />
                                            </Image.GestureRecognizers>
                                        </ic:CircleImage>
                                    </Grid>
                                </StackLayout>
                            </ViewCell>
                        </TableSection>
                        <TableSection x:Name="Daughters" Title="Daughter(s)">
                            <ViewCell>
                                <StackLayout>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20"/>
                                            <ColumnDefinition Width="2*"/>
                                        </Grid.ColumnDefinitions>
                                        <Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperDaughter},Path=Value}"/>

                                        <Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperDaughter" Increment="1" Maximum="10" Minimum="1" >
                                        </Stepper>
                                        <ic:CircleImage  Grid.Row="0" Grid.Column="2"  Source="sharp_group_add_black_18.png">
                                            <Image.GestureRecognizers>
                                                <TapGestureRecognizer Tapped="OnstepperDaughterValueChanged" />
                                            </Image.GestureRecognizers>
                                        </ic:CircleImage>
                                    </Grid>
                                </StackLayout>
                            </ViewCell>
                        </TableSection>

                    </TableRoot>
                </TableView>

                <StackLayout 
                         AbsoluteLayout.LayoutFlags="All"
                         AbsoluteLayout.LayoutBounds="1,1,0.25,0.25">

                    <StackLayout HorizontalOptions="End" VerticalOptions="End" Margin="0,0,0,0">
                        <Button Clicked="OnSubmit" Text="Submit" HorizontalOptions="End" 
                            ></Button>
                    </StackLayout>

                </StackLayout>

                </AbsoluteLayout>
                </ContentPage>

UserChildrenTabbedPage.xaml.cs

                 using FamilyTreeApp.Models;
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;

                using Xamarin.Forms;
                using Xamarin.Forms.Xaml;

                namespace FamilyTreeApp.Pages
                {
                    (XamlCompilation(XamlCompilationOptions.Compile))
                    public partial class UserChildrenTabbedPage : ContentPage
                    {
                        public int countSons = 1;
                        public int countDaughters = 1;

                        public UserChildrenTabbedPage()
                        {
                            InitializeComponent();
                        }

                        private void CreateEntryCells(int numCell, string textToBeCreated)
                        {
                            if (textToBeCreated.ToLower().Contains("son"))
                            {
                                for (int i = countSons; i<= numCell; i++)
                                {
                                    EntryCell entInput = new EntryCell
                                    {
                                        Placeholder = textToBeCreated + countSons
                                        //Text = "{Binding Spouse' + 1 + 'FirstName}"
                                        //HorizontalOptions = LayoutOptions.FillAndExpand
                                    };

                                    string txt = "{Binding" + textToBeCreated + countSons + "_FirstName}";
                                    entInput.SetBinding(EntryCell.TextProperty, txt);

                                    Sons.Add(entInput);
                                    ++countSons;

                                }
      
                            }
                            else
                            {
                                for (int i = countDaughters; i <= numCell; i++)
                                {
                                    EntryCell entInput = new EntryCell
                                    {
                                        Placeholder = textToBeCreated + countDaughters
                                        //Text = "{Binding Spouse' + 1 + 'FirstName}"
                                        //HorizontalOptions = LayoutOptions.FillAndExpand
                                    };

                                    string txt = "{Binding" + textToBeCreated + countDaughters + "_FirstName}";
                                    entInput.SetBinding(EntryCell.TextProperty, txt);

                                    Daughters.Add(entInput);
                                    ++countDaughters;

                                }


                            }
                        }

                        private void OnstepperDaughterValueChanged(object sender, EventArgs e)
                        {
                            CreateEntryCells(int.Parse(stepperDaughter.Value.ToString()), "Daughter");

                        }

                        private void OnstepperSonValueChanged(object sender, EventArgs e)
                        {

                            CreateEntryCells(int.Parse(stepperSon.Value.ToString()), "Son");

                        }

                        private void OnSubmit(object sender, EventArgs e)
                        {
                        }
                    }
                }

.How to post all the tabbed data to the web api through DTO object?

8 – Configurable Action Form Builder Not Called by Views Bulk Operations

I have a configurable Action that I implemented back in VBO 8.x-3.8, and it was working fine.

<?php

namespace Drupalmy_modulePluginAction;

use DrupalCoreActionConfigurableActionBase;
use DrupalCoreEntityDependencyTrait;
use DrupalCoreFormFormStateInterface;
use DrupalCoreSessionAccountInterface;

/**
 * Some description.
 *
 * @Action(
 *   id = "assign_distributor",
 *   label = @Translation("Assign Distributor to users"),
 *   type = "user",
 * )
 */
class AssignDistributor extends ConfigurableActionBase {

  use DependencyTrait;

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {
    $nid = $this->configuration('distributor_nid');
    // Add the nid to field_distributors.
    $entity->get('field_distributors')->appendItem((
      'target_id' => $nid,
    ));
    $entity->save();
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    $access = $object->access('update', $account, TRUE);

    return $return_as_object ? $access : $access->isAllowed();
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return (
      'distributor_nid' => '',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form('distributor_nid') = (
      '#type' => 'entity_autocomplete',
      '#title' => $this->t('Select Distributor'),
      '#target_type' => 'node',
      '#required' => TRUE,
      '#selection_handler' => 'default',
      '#selection_settings' => (
        'target_bundles' => ('distributor'),
      ),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration('distributor_nid') = $form_state->getValue('distributor_nid');
  }

}

Since then, I also started using Views Bulk Edit to do some bulk editing, and we ran into an issue (like this one) where the Apply button on the form will not work. At the same time, I figured out that what is not working with my custom action is that the buildConfigurationForm() method is not being called at all, and instead, it goes right to the execute(). method, and since no config data was entered, there is nothing to save.

I have tried rolling back versions of both VBE and VBO, and even the dev versions of both modules, but nothing has changed. It seems that the base problem is VBO. I will be filing an issue in the issue queue, but I’m curious to see if anyone has seen these issues with VBO besides me. Or, is there possibly something missing from my Action plugin above. It was working fine recently, so I’m not sure what might have changed that would have broken it.

woocommerce deposit Form with AJAX and shortcode won’t update but add to previous output

I am trying to create a product page where selecting a field defines a product and this triggers an AJAX call to display the woocommerce deposit form and add to cart submit button that correspond to the relevant product id.

The form that contains the deposit selection fields and submit button is displayed by using a shortcode which is called on page load with the default product.

Then, zhen clicking on the field that corresponds to the product you want to change to, I use an AJAX request to execute that shortcode again. I then try to replace the old form by the new form with innerhtml in Javascript, however for some reason the new form is always added after the old one. I can’t seem to replace that innerhtml content. Here is the code:

This is contained on the page:

//div to be filled with product deposit and add to cart form
<div id="adddepositsection">(add_product id="17364")</div>

//AJAX call on field click to execute the shortcode and replace the innerhtml
jQuery('#product2').on('click', function(){
document.getElementById("product1").className = "unselectedbox";
document.getElementById("product2").className = "selectedbox";
document.getElementById("product3").className = "unselectedbox";

jQuery.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: {
            action: 'addfunctionshortcode',
            // add your parameters here
            productid: "17372"
        },
        success: function (output) {
document.getElementById("adddepositsection").innerHTML = output; 
}
        });


});

Shortcode function to display the deposit and add to cart button as well as function to execute that shortcode via AJAX in functions.php:

 //Display deposit choice and add to cart shortcode
    function add_product_display( $atts ) {
      $atts = shortcode_atts( array(
            'id' => null,
        ), $atts, 'bartag' );
    
        
            if( intval( $atts('id') ) > 0 && function_exists( 'wc_get_product' ) ){
             $product = wc_get_product( $atts('id') );
        ?>
    
        <form class="cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'>
            
            <div class="wc-deposits-wrapper <?php echo WC_Deposits_Product_Manager::deposits_forced( $product->get_id() ) ? 'wc-deposits-forced' : 'wc-deposits-optional'; ?>">
        <?php if ( ! WC_Deposits_Product_Manager::deposits_forced( $product->get_id() ) ) : ?>
            <ul class="wc-deposits-option">
                <li>
                    <input type="radio" name="wc_deposit_option" value="yes" id="wc-option-pay-deposit" <?php checked( $default_selected_type, 'deposit' ); ?> />
                    <label for="wc-option-pay-deposit">
                        <?php esc_html_e( 'Pay Deposit', 'woocommerce-deposits' ); ?>
                    </label>
                </li>
                <li>
                    <input type="radio" name="wc_deposit_option" value="no" id="wc-option-pay-full" <?php checked( $default_selected_type, 'full' ); ?> />
                    <label for="wc-option-pay-full">
                        <?php esc_html_e( 'Pay in Full', 'woocommerce-deposits' ); ?>
                    </label>
                </li>
            </ul>
        <?php endif; ?>
    </div>
            <div class="addcartcontainer">
                
    <?php if ( $product->is_in_stock() ) {  
             if (pll_current_language() == "en"   ) { ?>
                    <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">BUY NOW</button> <?php
                     }
                    elseif (pll_current_language() == "fr"){ ?>
                        <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">ACHETER MAINTENANT</button> <?php
                    }
                    elseif (pll_current_language() == "it"){ ?>
                        <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">ACQUISTA ORA</button> <?php
                    }
             }
                else { 
     if (pll_current_language() == "en"   ) { ?>
                    <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">SOLD OUT</button> <?php
                     }
                    elseif (pll_current_language() == "fr"){ ?>
                        <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">EPUISE</button> <?php
                    }
                    elseif (pll_current_language() == "it"){ ?>
                        <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="addtocartsubmit">SOLD OUT</button> <?php
                    }
                 } ?>
            </div>
    
        </form>
    
    
    <?php
    
    }
    }
    add_shortcode( 'add_product', 'add_product_display' );

//Function called by AJAX to execute shortcode
// register the ajax action for authenticated users
add_action('wp_ajax_addfunctionshortcode', 'addfunctionshortcode');

// register the ajax action for unauthenticated users
add_action('wp_ajax_nopriv_addfunctionshortcode', 'addfunctionshortcode');

// handle the ajax request
function addfunctionshortcode() {
    $atts('id') = $_REQUEST('productid');
            echo  add_product_display( $atts );
die();
}