Opencart 2.0.3.1 - contact form not validating - contact-form

I am using the default Opencart 2.0.3.1. Everything works great, except for the contact form. For some reason, it does not validate the form, and gives no errors after submitting. Any ideas? You can view it here: https://sgroiinnovations.com/index.php?route=information/contact
I can not figure it out. The same type of validation is used for entering a review, and it works correctly. In the contact form, when submit is clicked, it submits the form with no information entered. No errors are provided before or after the page is submitted.
In the contact.php, there is no question that it is calling the validate function below, but again for some reason, the submit button just seems to submit the page (form) without this process.
I'm guessing there is something simple that I am missing, but I can't catch it. Any help would be appreciated. Thx
protected function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
if ($this->config->get('config_google_captcha_status')) {
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
$recaptcha = json_decode($recaptcha, true);
if (!$recaptcha['success']) {
$this->error['captcha'] = $this->language->get('error_captcha');
}
}
return !$this->error;
}

Problem fixed. The issue was that I was forwarding http to https using .htaccess. This blew up the contact form because of non-secure to secure. Not sure why, but I removed the redirect and it works.

Related

ReactJS - Front-end form error handler/validation

I'm building a simple donation app in ReactJS. Here is a working version here:
https://stackblitz.com/edit/react-grzdgz
I've never done form error validation though. So if someone doesn't fill out a field, I'd like an error message to pop up, which says something like "this field must be completed".
I've been trying to follow this tutorial:
https://learnetto.com/blog/how-to-do-simple-form-validation-in-reactjs
But I'm kinda getting lost, about how I can pass these functions/error messages, into my form, which sits in a seperate module. In the demo, everything sits in one file.
But in my app, my form sits seperately to index.js. So I link to it in index.js.
I'm almost there, I just need some help connecting everything up.
Can anyone help me get form error validation working?
The error handling functions all sit here:
https://stackblitz.com/edit/react-grzdgz
The form itself sits here:
https://stackblitz.com/edit/react-grzdgz?file=components%2FForm.js
And some form errror heres:
https://stackblitz.com/edit/react-grzdgz?file=components%2FFormErrors.js
Any help would be great!
Thank you!
On the submit, I would have a method called: validateFields, which would validate all field like you want (instead of using the default validator of html, which doesn't work on some browser). In the method, I would save all the field with an error.
If the error list (or object) is not empty, you use an alert or popup react-popup
If there are no error, you can call submit method.
Basically, it would look something like:
export default class DumbComponent extends React.Component {
state = {} // all your field value
validateField = () => {
let error = []
//Validate all your field
if (error.length === 0) {
this.submit()
} else {
this.showError() // You decide the way
}
}
render() {
return (
<Form>
<FieldOne />
<Field2 />
<SubmitButton onSubmit={this.validateField} />
</Form>
)
}
}
Hope it answer your question!

Bootstrap Validation Manipulation AngularJS

I have an input box for a new user to put in a userid. I want to dynamically check if the userid is already taken on-blur. I'm using bootstrap validation for form validation, and I'm having a hard time figuring out how to make it do what I want. In the validation, I have this code currently for userid:
userid: {
container: '#useridMessage',
validators: {
notEmpty: {
message: '*Required'
},
stringLength: {
min:3,
message: 'Username must be at least 3 characters long'
}
}
},
What I want to be able to do in there is call a function I have for the on-blur action:
$scope.userCheck = function () {
userAPIService.getUserDetails($scope.user.username).success( function ( data ) {
if(data.Status == 0){
//make box red and invalid
}
}).error( function ( error ) {
$scope.status = "Error is checking Username availability";
})
}
My backend function is the getUserDetails which is a GET function. I was planning on, as is shown in the code, to check if the userid is a valid one (data.status == 0) already in our system and notify the user after that it is already taken. My desire is to maintain good coding practice and not by pass my bootstrap validation ( which is working well for everything else ) and make both work together, but since bootstrap validation is kind of a black box, I'm not sure how to do this.
Question: How can I get the validation to check some boolean variable, or how can I get the validation to make the backend call and then analyze the result like I want?
Thoughts:
Ideally I'd like to be able to call the onblur function which would set some boolean and then the validation would just look at the validation, but I'm open to any idea to get this right. Thanks
I wonder if creating a custom validation directive would be a good approach. There's a good overview here How to add custom validation to an angular js form, also in the Custom Validation section of the Angular JS Forms documentation. Hope this helps.

Drupal - magnific popup only works when logged in

I am using magnific popup JS (http://dimsemenov.com/plugins/magnific-popup/) to produce a popup for a youtube video on my Drupal site. The implementation works fine, but only if I am logged into Drupal. If I am not logged in, the popup link will just go the the youtube page (eg jQuery not initialising).
I suspect there may be something going on with Drupal loading a different version of jQuery when I am logged in. It seems that I may be able to add something to my template file to fix this. Haven't figured it out yet (https://www.drupal.org/node/2165555)
I do not have access to add jQuery update module.
Fixed. Added below snippet to template.php to force a later version of jQuery to load.
function theme_name_js_alter(&$javascript) {
$node_admin_paths = array(
'node/*/edit',
'node/add',
'node/add/*',
'node/*/extend_review_date',
);
$replace_jquery = TRUE;
if (path_is_admin(current_path())) {
$replace_jquery = FALSE;
} else {
foreach ($node_admin_paths as $node_admin_path) {
if (drupal_match_path(current_path(), $node_admin_path)) {
$replace_jquery = FALSE;
}
}
}
// Swap out jQuery to use an updated version of the library.
if ($replace_jquery) {
$javascript['misc/jquery.js']['data'] = '//code.jquery.com/jquery-1.7.0.min.js';
}
}

cakephp: no save, no validate errors, no callbacks, empty sql log

In my controller i have this add function:
public function add(){
$this->layout = false;
if($this->request->is('post')){
$this->Paciente->create();
$this->Paciente->set($this->request->data);
if ($this->Paciente->validates()) {
if($this->Paciente->save()){
$this->set('status', '200');
} else {
// debug($this->Paciente->validationErrors);
// ini_set('memory_limit', '-1');
// var_dump($this->Paciente);
$this->set('status', '101');
// $log = $this->Paciente->getDataSource()->getLog(false, false);
// debug($log);
// die;
}
} else {
// didn't validate logic
// $errors = $this->Paciente->validationErrors;
// debug($errors);
$this->set('status', '100');
}
} else
$this->set('status', '404');
}
I'm sending the post info and the status is always 101. As you can see I have tried a lot to find out where is the error, but no luck.
Also I don't have any callback in my Model (beforeSave, afterSave...)...
Anyone knows what is happening?
Your
if ($this->Paciente->validates()) {
if($this->Paciente->save()) {
}
is wrong.
You are validating twice.
Please - as documented - either use false (save(null, false)) to not invalidate twice or simply remove the validates() part here.
You can directly do:
if ($this->Paciente->save($this->request->data)) {}
This itself is unlikely causing your issue, though.
Or do you have some custom validation rules that on second (and faulty) trigger will make a field invalidate?
You can confirm that by checking $this->Paciente->validationErrors afterwards. It should be empty. If it does not save (and it's for sure no callback), and if it does not throw exceptions due to SQL errors then it most likely are your validation rules.
The problem was in the way i was sending the post info:
I was setting the variables as data['Model']['var'] and the correct way is data[Model][var]
Thanks #mark, #AD7six, #liyakat and #Alex for your help in the problem.
I can't imagine. When you set your array values like above it would likely break in php5.3 >

Can I make CakePHP return a suitable status code based on certain conditions?

This question is slightly related to my old post Dealing with Alias URLs in CakePHP
After much thought, I am exploring the option of having a custom 404 script in my Cake App, that is reached when a URL does not map to any controllers/actions. This script would check $this->here and look it up in a database of redirects. If a match is found it would track a specific 'promo' code and redirect.
I'm thinking status codes. Can I make my script return a suitable status code based on certain conditions? For example:
URL matches a redirect - return a 301
URL really does not have a destination - return a 404.
Can I do this?
EDIT:
What about this? Anyone see any problems with it? I put it in app_controller.
function appError($method, $params) {
//do clever stuff here
}
This should work. Assuming you redirect 404's at a LegacyUrls::map() controller action. The code needs to be stored in app/app_error.php:
<?php
class AppError extends ErrorHandler{
function error404($params) {
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch('/legacy_urls/map', array('broken-url' => '/'.$params['url']));
exit;
}
function missingController($params) {
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch('/legacy_urls/map', array('broken-url' => '/'.$params['url']));
exit;
}
}
?>
Good luck!
I've always created app\views\errors\missing_action.ctp and app\views\errors\missing_controller.ctp
Cake will automatically display one of those views when a url does not map out to a controller or its methods.
Unless there is a certain need for the error codes that you did not give, this would work perfectly!
I'd like to augment felixge's answer.
This version outputs a 404 error to the browser:
class AppError extends ErrorHandler
{
function _outputMessage($template)
{
if ($template === 'error404') {
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch('legacy_urls/map', array('broken-url' => '/'.$params['url']));
return;
}
parent::_outputMessage($template);
}
}

Resources