Access form results
Permalink
Hi,
I'm using the form block to my user order things on my website - which works wonderful.
Next, I'd like to submit for each order the results to Google Analytics (eCommerce tracking). But I can't find out how to access the values that the user typed in.
In PHP I'd do something like this ($city, $country, etc. are the input values of the form):
Could anybody give me a hint how to solve this?
Thanks a lot!
Ronny
I'm using the form block to my user order things on my website - which works wonderful.
Next, I'd like to submit for each order the results to Google Analytics (eCommerce tracking). But I can't find out how to access the values that the user typed in.
In PHP I'd do something like this ($city, $country, etc. are the input values of the form):
// Calculate price $price = ($version == "full") ? 7.90 : 3.99; // Generate random transaction ID $transID = rand(1,10000000); $extraTracking = "pageTracker._addTrans(\"$transID\", \"\", \"$price\", \"0\", \"0\", \"$city\", \"\", \"$country\"); pageTracker._addItem(\"$transID\", \"$version\", \"$version\", \"My product\", \"$price\", \"1\"); pageTracker._trackTrans();";
Could anybody give me a hint how to solve this?
Thanks a lot!
Ronny
Thanks for the hint!
Extending the file concrete/blocks/form/controller.php indeed worked:
But not sure if this is really the right way to solve my initial issue. After all, I changed a base class (copy&paste of the form/ directory doesn't look my better to me).
Extending the file concrete/blocks/form/controller.php indeed worked:
if($this->redirectCID > 0) { $pg = Page::getByID($this->redirectCID); if(is_object($pg)) { // Begin extension: Add parameters foreach ($questionAnswerPairs as $key => $value) $values .= urlencode($value["question"]) . "=" . urlencode($value["answer"]) . "&"; $this->redirect($pg->getCollectionPath() . "?" . $values); // $this->redirect($pg->getCollectionPath()); // End extension: Add parameters } else { // page didn't exist, we'll just do the default action header("Location: ".$refer_uri."&surveySuccess=1&qsid=".$this->questionSetId."#".$this->questionSetId); exit; } }
But not sure if this is really the right way to solve my initial issue. After all, I changed a base class (copy&paste of the form/ directory doesn't look my better to me).
Yes, there's probably a cleaner solution -- but copying the directory up to override the core block is actually much better than modifying the code in the concrete directory because you won't lose your mods when you upgrade...
It seems like you could check $qsID in there, and if it corresponds to your order form, have it call out to a function to submit to google. You'd probably want to pass that function the $questionAnswerPairs array