Last active
July 8, 2025 18:56
-
-
Save MegaphoneJon/cd7b6e04917dddcf7c67072c8f804ba6 to your computer and use it in GitHub Desktop.
Takes a POST string from stdin for an event reg and submits it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| // To use this, put this line at the start of CRM_Core_Controller::__construct() - `$ignoreKey = TRUE;` | |
| // Load CiviCRM | |
| eval(`cv php:boot`); | |
| $config = CRM_Core_Config::singleton(); | |
| // File path from args or STDIN | |
| $fh = (isset($argv[1]) && file_exists($argv[1])) | |
| ? fopen($argv[1], 'r') | |
| : fopen('php://stdin', 'r'); | |
| while ($line = fgets($fh)) { | |
| $post = []; | |
| parse_str(trim($line), $post); | |
| preg_match('/register\?id\=(\d+)/', $post['entryURL'], $matches); | |
| $post['id'] = $matches[1]; | |
| $post['reset'] = 1; | |
| // Strip qfKey and other irrelevant keys | |
| unset($post['qfKey'], $post['_qf_Register_upload'], $post['entryURL'], $post['bypass_payment']); | |
| // Initialize the form | |
| $formName = 'CRM_Event_Form_Registration_Register'; | |
| $form = new $formName(); | |
| $_REQUEST = $post; | |
| $form->controller = new \CRM_Event_Controller_Registration(); | |
| $_SESSION['_' . $form->controller->_name . '_container']['values'][$form->getName()] = $post; | |
| #$form->controller = new \CRM_Core_Controller(); | |
| $form->_submitValues = $post; | |
| $form->controller->addPage($form); | |
| try { | |
| // Load data | |
| $form->buildQuickForm(); // sets up the fields | |
| $form->preProcess(); | |
| $form->postProcess(); | |
| // If there's no add'l participants or confirmation screen, registration happened in the postProcess. Otherwise, do it now. | |
| if (!$form->getParticipantID()) { | |
| $form->processRegistration($form->get('params')); | |
| } | |
| echo "✅ Success for: " . ($post['email-Primary'] ?? '[no email]') . "\n"; | |
| } catch (Exception $e) { | |
| echo "❌ Error: " . $e->getMessage() . "\n"; | |
| } | |
| } | |
| fclose($fh); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment