How to determine which of multiple submit buttons the user clicked

nlheath 05 Jun, 2025

I have a CF7 form with two submit buttons with different texts, which should result in redirecting the user to different forms.  For each button, under Behaviors, I select Local Vars, and then add a local variable named dir.  I set the variable to different values for each button, PREV for the first and NEXT for the second.

In the actions for this form, I execute a segment of php code as follows:

$dir = $this->get("dir","");

if ($dir == "PREV")  {$this->data ['page_num'] = 1;}

else {$this->data ['page_num'] = 3;}

but the first condition is never met, so the value of page_num always results in 3.

What am I doing wrong? 

Is there another way to determine which button was clicked?

Max_admin 08 Jun, 2025
Answer

The way to do this is to give each button a different name, and check if the name exists in the form data or not, usually using a PHP action with Events behavior

And for best results you should use the new ChronoForms v8 which has the latest improvements and tutorials

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.