Skip to main content
Version: v4

Form Message

The FormMessage class is used to create an interactive form message that can be sent via CometChat. It extends the InteractiveMessage class from CometChat.

Constructor

NameTypeDescription
receiverIdstringThe ID of the receiver
receiverTypestringThe type of the receiver
titlestringThe title of the form
formFieldsArray<ElementEntity>The fields of the form
submitElementButtonElementThe submit button of the form

Class Usage

How to create an instance of the FormMessage class:

List<ElementEntity> elementEntities = new ArrayList<>();
//here we have created the object to display the TextInput into the form
TextInputElement textInputElement1 = new TextInputElement("element1", "Name");
TextInputElement textInputElement2 = new TextInputElement("element2", "Last Name");
TextInputElement textInputElement3 = new TextInputElement("element3", "Address");
textInputElement3.setMaxLines(5);
elementEntities.add(textInputElement1);
elementEntities.add(textInputElement2);
elementEntities.add(textInputElement3);


//here we have created the navigation action which will executated on a click of button
URLNavigationAction urlNavigationAction = new URLNavigationAction("https://www.cometchat.com/");

ButtonElement submitElement = new ButtonElement("idSubmit", "submit", urlNavigationAction);
submitElement.setDisableAfterInteracted(true);
FormMessage formMessage = new FormMessage(receiverId, receiverType, elementEntities, submitElement);
formMessage.setTitle("Socity Survey");
formMessage.setAllowSenderInteraction(true); // this will confirm if sender can interact with that form or not

Send Form Message

formMessage.setSender(CometChatUIKit.getLoggedInUser());
formMessage.setSentAt(System.currentTimeMillis() / 1000);
formMessage.setReceiver(user); // set Receiver user/group object

CometChatUIKit.sendFormMessage(formMessage, false, new CometChat.CallbackListener<FormMessage>() {
@Override
public void onSuccess(FormMessage formMessage) {

}

@Override
public void onError(CometChatException e) {
e.printStackTrace();
}
});