OpenCart3+Journal3主题下Twig模板输入值无法在控制器获取求助
Hey there, let's work through this issue step by step—getting that post value into your controller can be tricky with Journal3's custom checkout flow, but we'll nail it down:
1. Double-check your Twig field placement & spelling
First, confirm your custom input is properly nested inside the checkout form, and the name attribute matches exactly what you're trying to fetch in the controller. Also, watch out for typos (you wrote reciept_name—is that intentional, or should it be receipt_name? Mismatched spelling is one of the most common culprits here).
Example of correct field structure in theme/journal3/template/journal3/checkout/checkout.twig:
<!-- Make sure this is inside the main checkout <form> tag --> <div class="form-group"> <label class="control-label">{{ text_receipt_name }}</label> <input type="text" name="reciept_name" value="{{ reciept_name }}" class="form-control" /> </div>
Also verify the form has method="post" and the correct action pointing to the checkout route.
2. Check Journal3's AJAX checkout data collection
Journal3 often uses AJAX to submit checkout data instead of traditional form posts. That means your custom field might not be automatically included in the data sent to the controller.
Look for Journal3's checkout JS file (usually journal3/js/checkout.js), and find functions like getFormData() or prepareCheckoutData. You'll need to add your field to the data object being sent. For example:
// Inside the data collection function var formData = { // Existing fields... reciept_name: $('input[name="reciept_name"]').val() };
3. Verify you're checking for the value in the right controller method
In controller/journal3/checkout.php, are you trying to access $this->request->post['reciept_name'] in the correct method? Checkout flows have multiple steps—if you're looking in index() but the submission happens in confirm(), you won't see the value.
Always add a check to avoid errors, and use logging to debug:
// Put this in the method handling the checkout submission (e.g., confirm()) if (isset($this->request->post['reciept_name'])) { $receipt_name = $this->request->post['reciept_name']; // Log the value to confirm it's coming through $this->log->write('Received receipt name: ' . $receipt_name); } else { $this->log->write('reciept_name not found in POST data'); }
4. Clear all caches
OpenCart and Journal3 cache aggressively—old template or JS files might be overriding your changes:
- Clear OpenCart's system cache (Go to System > Cache Management and clear all)
- Clear Journal3's cache (Go to Journal3 > Settings > Cache and flush all)
- Clear your browser's cache or test in incognito mode
5. Check if POST data is being filtered
Sometimes OpenCart or Journal3's validation filters out unrecognized fields. To confirm, log all POST data in your controller:
$this->log->write('Full POST data: ' . print_r($this->request->post, true));
If reciept_name doesn't show up here, the issue is with data not being sent from the frontend. If it does show up but you can't access it directly, check for validation rules that might be stripping the field.
6. Confirm multi-store/language compatibility
If you're using a multi-store or multi-language setup, make sure you've modified the correct template file for your active store/language, and that Journal3 is set to load the modified template.
内容的提问来源于stack exchange,提问作者Anmol singh

