Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom fields into proactive form window #540

Closed
onlyindia opened this issue Nov 8, 2014 · 4 comments
Closed

Adding custom fields into proactive form window #540

onlyindia opened this issue Nov 8, 2014 · 4 comments

Comments

@onlyindia
Copy link

onlyindia commented Nov 8, 2014

Proactive form window should have option to add custom fields like this:

LHCChatOptions.attr = new Array();
LHCChatOptions.attr.push({'name':'City','value':'','type':'text','size':10,'req':true});
LHCChatOptions.attr.push({'name':'State','value':'','type':'text','size':10,'req':true});

@onlyindia
Copy link
Author

If someone is in need of this feature then ask in comment. I've implemented this in my code.

@remdex
Copy link
Contributor

remdex commented Nov 11, 2014

Could you share a code so i could incorporate in official version.

@onlyindia
Copy link
Author

onlyindia commented Nov 11, 2014

yes why not.. I'm using old version however you will get idea by having look.

Step- 1
Inside design/defaulttheme/ tpl/lhchat/readoperatormessage.tpl.php

Right after

<?php include_once(erLhcoreClassDesign::designtpl('lhchat/part/department.tpl.php'));?>

add this

Step -2
and then add this code in modules/readoperatormessage.php

right after
$inputData->validate_start_chat = false;

add below

$inputData->name_items = array();
$inputData->value_items = array();
$inputData->value_sizes = array();
$inputData->value_types = array();

and then right after

$validationFields['Userphone'] = new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw' );

add below

// validate additional_data code in proactive chat
$validationFields['name_items'] = new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw',
null,
FILTER_REQUIRE_ARRAY
);

    $validationFields['values_req'] = new ezcInputFormDefinitionElement(
            ezcInputFormDefinitionElement::OPTIONAL, 'string',
            null,
            FILTER_REQUIRE_ARRAY
    );

    $validationFields['value_items'] = new ezcInputFormDefinitionElement(
            ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw',
            null,
            FILTER_REQUIRE_ARRAY
    );

    $validationFields['value_types'] = new ezcInputFormDefinitionElement(
            ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw',
            null,
            FILTER_REQUIRE_ARRAY
    );

    $validationFields['value_sizes'] = new ezcInputFormDefinitionElement(
            ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw',
            null,
            FILTER_REQUIRE_ARRAY
    );

    $validationFields['value_show'] = new ezcInputFormDefinitionElement(
            ezcInputFormDefinitionElement::OPTIONAL, 'string',
            null,
            FILTER_REQUIRE_ARRAY
    );

// end validate additional_data code in proactive chat

and then right after

if ($userInstance->requires_email == 1) {
if ( !$form->hasValidData( 'Email' ) ) {
$Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat','Please enter a valid email address');
} else {
$inputData->email = $chat->email = $form->Email;
}
}

add below

// validate and insert additional_data code in proactive chat
if ( $form->hasValidData( 'name_items' ) && !empty($form->name_items))
{
$valuesArray = array();
if ( $form->hasValidData( 'value_items' ) && !empty($form->value_items))
{
$inputForm->value_items = $valuesArray = $form->value_items;
}

        if ( $form->hasValidData( 'values_req' ) && !empty($form->values_req))
        {
            $inputForm->values_req = $form->values_req;
        }

        if ( $form->hasValidData( 'value_types' ) && !empty($form->value_types))
        {
            $inputForm->value_types = $form->value_types;
        }

        if ( $form->hasValidData( 'value_sizes' ) && !empty($form->value_sizes))
        {
            $inputForm->value_sizes = $form->value_sizes;
        }

        if ( $form->hasValidData( 'value_show' ) && !empty($form->value_show))
        {
            $inputForm->value_show = $form->value_show;
        }

        $inputForm->name_items = $form->name_items;

        $stringParts = array();
        foreach ($form->name_items as $key => $name_item) {    
            if (isset($inputForm->values_req[$key]) && $inputForm->values_req[$key] == 't' && ($inputForm->value_show[$key] == 'b' || $inputForm->value_show[$key] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) {
                $Errors[] = trim($name_item).' : '.erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat','is required');
            }           
            $stringParts[] = trim($name_item).' - '.(isset($valuesArray[$key]) ? trim($valuesArray[$key]) : '-');
        }

        $chat->additional_data = implode(', ', $stringParts);
    } 
    // end of additional_data code in proactive chat

that's all you need to do.. updating two files :)

and don't forget to update email template code {additional_data}

remdex added a commit that referenced this issue Nov 30, 2014
@remdex
Copy link
Contributor

remdex commented Nov 30, 2014

Implemented. Pending new version release.

@remdex remdex closed this as completed Nov 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants