Announcement

Collapse
No announcement yet.

Web-to-lead capturing home and mobile number : store data to field with list optins

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web-to-lead capturing home and mobile number : store data to field with list optins

    Hi
    I am making use of the excellent web-to-lead facility and instructions using web browser only code (https://docs.espocrm.com/administration/web-to-lead/)
    Working fine for "standard" fields, but I want to capture both home and phone fields.
    I've adjusted the form to do so, but I am not sure of the syntax/format to use for the payload in the script.
    E.g.
    var payloadData = {
    firstName: webToLeadFormElement.firstName.value,
    lastName: webToLeadFormElement.lastName.value,
    emailAddress: webToLeadFormElement.emailAddress.value,
    phoneNumber['Home']: webToLeadFormElement.phoneNumber.value
    phoneNumber['Mobile']: webToLeadFormElement.mobileNumber.value
    };
    But my guess for phoneNumber['Home'] doesn't work
    I can't trace in the forum or documentation how to reference a list item in a field

    Any help please ?
    Many thanks.

  • #2
    Hello,

    see this :

    PHP Code:

    $o 
    = (object) [ 'phoneNumber' => $phoneMobile'type' => 'Mobile''primary' => true,];
    $phoneNumberData[] = $o;

    $o = (object) [ 'phoneNumber' => $phoneHome'type' => 'Home''primary' => false,];
    $phoneNumberData[] = $o
    and then save as :

    'phoneNumberData' => $phoneNumberData,

    Comment


    • #3
      Ah ok, thank you
      So the data is passed as an object.
      Still struggling with this as javascript in the browser (don't have PHP on the webserver as it is going into a static HUGO site)

      Comment


      • #4
        This gives me 500 error from espo web-to-lead link
        Code:
        phoneNumber: {
        "phoneNumber": webToLeadFormElement.phoneNumber.value,
        "type": "Home",
        "primary": true},
        phoneNumber: {
        "phoneNumber": webToLeadFormElement.mobileNumber.value,
        "type": "Mobile",
        "primary": false}

        Comment


        • #5
          Also (i think) related
          I have a custom field contactType defined as a checklist with four options
          I would like to add this to the web-to-lead payload something like this
          (no wed form input element, static value determined by the page the visitor is on)
          Code:
          var payloadData = {
              contactType: "Type 2",
              ....
              ....
          }
          But doesn't seem to work.
          What is the correct syntax for assigning a value to e.g. the 2nd item in a checklist ?

          Comment


          • #6
            Hello,
            emum is as a string : name => 'coucou' .. .so for enum : enumfield => 'value'

            for phoneNumber.. it's not as you have write. i give sample for back-end how is.

            for one phone : phoneNumber => 'value'

            but you have 2 phone, so i think you must send from client side data so to api and respect "phoneNumberData" as name of fieldData :

            phoneNumberData => { [phoneNumber => .... ], [ phoneNumber] => ... }



            Comment


            • #7
              Thank you, that's interesting you say it should be phoneNumberData

              Originally posted by item View Post
              so i think you must send from client side data so to api and respect "phoneNumberData" as name of fieldData :

              phoneNumberData => { [phoneNumber => .... ], [ phoneNumber] => ... }
              The Lead Capture page in Administration says the payload should be just "phoneNumber":
              Code:
              {
                "firstName": "FIRST_NAME",
                "lastName": "LAST_NAME",
                "emailAddress": "EMAIL_ADDRESS",
                "addressStreet": "ADDRESS_STREET",
                "addressStreet2": "ADDRESS_STREET2",
                "addressCity": "ADDRESS_CITY",
                "addressPostalCode": "ADDRESS_POSTAL_CODE",
                "addressState": "ADDRESS_STATE",
                "addressCountry": "ADDRESS_COUNTRY",
                "phoneNumber": "PHONE_NUMBER",     <----
                "facebook": "FACEBOOK",
                "twitter": "TWITTER",
                "description": "DESCRIPTION",
                "dateofbirth": DATEOFBIRTH
              }
              Let me try your approach.

              Does the syntax " phoneNumber => 'value' " work in Javascript on a web page ?
              Last edited by timconsidine; 03-07-2021, 08:13 AM.

              Comment


              • #8
                Hello,
                yes , phoneNumber => '0345566'. must work,

                but as you have multiple phoneNumber, you need to send as array and as phoneNumberData field.
                open googlechrome (F12), and see payload when you add multiple phonefield.

                Comment

                Working...
                X