Score:1

How can I use EntityForm ::save() in a custom module?

ru flag

How can i call public function ContactFormEditForm::save. My goal is refer to return value, do something like email, custom logged message, etc.

Refer to api."Return value int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed."

Un myCustom.module file how to do: if contact Form == specific Form, and if the form submitted. $value = $form->save():

how do custom module know when user submitted ? hook for entity Form saved ? Must use Event ? i check some docs, but for dispatched to entity Form save(). same question, how Event know the form saved ?

pls give some direction, my concept is not clear.

thks

apaderno avatar
us flag
Welcome to Drupal Answers! Since this is a question about code, we need to see the code you wrote so far. If you are asking the question before writing code, you are asking the question too early. If the question is asked because you do not understand what the documentation says, the question must be explicit about that. From the question is not clear what exactly you do not understand in achieving the described task.
user76445 avatar
ru flag
Sorry for late reply, this is also 22:00 in my side. There are no code at all, because don't know where to start, nothing to hide, this is OOP concept problem, So far my Drupal life is only hook function, i just want to know how to get return value form entityForm:save(), someone has ans me, again use hook_form_alter. my programming skill is poor, but will keep studying, next time make sure post here only for coding problem, thanks.
4uk4 avatar
cn flag
IMHO this is a valid question. It's somewhat counterintuitive that the form class method save() is called by the submit element in the form array and it could use an explanation.
apaderno avatar
us flag
The question in the question body is *How can I call `ContactFormEditForm::save()`?* The question does not make clear where `ContactFormEditForm::save()` would be called nor does it show the code that would call `ContactFormEditForm::save()`.
apaderno avatar
us flag
Except in the case of a class that extends `ContactFormEditForm`, I cannot think of code that would need to call `ContactFormEditForm::save()`. It seems that calling `ContactFormEditForm::save()` is what the OP thinks to be the solution; if the question shows the used code, answers can at least say what is wrong in the code and what the correct solution is.
apaderno avatar
us flag
The post is not clear nor does it contain enough details; if the answer is that `ContactFormEditForm::save()` should be listed in the form submission handlers, then the question is too broad. Furthermore, there are more than a question asked in a single post; posts need to be focused on one problem only; that is why we have the *Needs more focus* closing reason.
Score:0
cn flag

This is a submission handler. Use a form alter hook and inspect the existing #submit array, you probably see the ::save() method already registered:

$form['actions']['submit']['#submit']

How do custom module know when user submitted?

Add your own submit handler to this array. See Add a custom submission handler to a form

user76445 avatar
ru flag
Thanks your very much !!! will try.....
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.