Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting names by comma causes problems #1

Closed
boboldehampsink opened this issue May 5, 2021 · 2 comments
Closed

Splitting names by comma causes problems #1

boboldehampsink opened this issue May 5, 2021 · 2 comments

Comments

@boboldehampsink
Copy link
Contributor

I have had a visitor that put its name like "Lastname, Firstname". Because of the comma splitting in Settings.php it makes two names out of it (with one email). It gives me this error:

ValueError: array_fill(): Argument #2 ($count) must be greater than or equal to 0
  File "/app/vendor/miranj/craft-contact-form-tuner/src/models/Settings.php", line 117, in array_fill
    $names = array_merge($names, array_fill(0, count($emails) - count($names), ''));
  File "/app/vendor/miranj/craft-contact-form-tuner/src/models/Settings.php", line 117, in miranj\contactformtuner\models\Settings::prepEmailConfig
    $names = array_merge($names, array_fill(0, count($emails) - count($names), ''));
  File "/app/vendor/miranj/craft-contact-form-tuner/src/models/Settings.php", line 54, in miranj\contactformtuner\models\Settings::getCcConfig
    $emails = $this->prepEmailConfig($this->ccEmail, $this->ccName);

It should handle this more properly

@rungta
Copy link
Member

rungta commented May 5, 2021

Thank you for reporting this @boboldehampsink.

Sounds like the ccEmail and ccName values are based on user submitted data in your project. If you want to avoid triggering the plugin’s comma splitting logic, you can set both these values to be arrays instead of strings. When the value is already an array, the plugin will use that instead of attempting to disambiguate it. So if you are sure to only support a single CC recipient, something like this might do the trick:

$config = [];
$request = Craft::$app->request;
if (!$request->getIsConsoleRequest() && $request->getBodyParam('action') == 'contact-form/send') {
    $config['ccEmail'] = [$request->post('ccEmail')];
    $config['ccName'] = [$request->post('ccName')];
}

return $config;

@boboldehampsink
Copy link
Contributor Author

@rungta thanks, that seems like a good solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants