Submit Multiple Forms With One Button


I have 2 form on the same page:

  1. First form is embed form from external website (vTiger webform) with action="https://***/crm/modules/Webforms/capture.php" method="post"
  2. Second form is FormIt-based form with preHook, which generate “form name”, “user_id” and “form_id” (value from TV). I save data from this form in another column is SQL-db. This form has action="[[~[[*id]]]]"

If i click send-button one them then work (send data) only 1 form.

I’ve tried via JavaScript and jQuery but work only 1 form:

document.getElementById("submit").onclick = function() {

How to send all both of them via one send-button?


1 Like

I think you have to send at least one of these forms with AJAX.
($.ajax() or $.post() when using jQuery)

Or maybe you can combine the 2 forms and then create a custom hook snippets for FormIt that makes the request to the webform using cURL.

1 Like

Hi halftrainedharry,
Do you have any sample of code with curl for this hook, please?

I don’t have any idea how to do it. I know how to download something via curl or create any API-connection vi curl but no idea how to use it in the hook.

I don’t have any code to share, but it should work pretty much the same as a post-request to an API.

In the hook snippet read the values of the FormIt fields with

$email = $hook->getValue('email');
$allFormFields = $hook->getValues();

and then probably something like this. (Maybe google for actual examples.)

$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);

$data = array(
    'foo' => $allFormFields["foo"]

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1 Like

Can you make it one form with two identical submit buttons?

Hi Bob,
I don’t understand what do you mean. It can’t be one form because first form send data to external website, second form is form with FormIt2db-hook.

Do you can explain me, please?

I understood you to mean you wanted both forms to always be submitted together. If that’s the case, There’s no reason a single form can’t both write to the DB and send data to an external website.

Maybe I misunderstood you.

Hi Bob,
How to do it? Only via curl or via Ajax?

I need to remember user if user has once sent the form.

Either one would work, but Ajax would require a custom processor. I think I’d do it all in PHP with cURL. You could use the remote_key (string) field of the user object to record whether they’ve sent the form.