Skip to content

Commit

Permalink
Merge pull request #671 from nishizoe/t-4557
Browse files Browse the repository at this point in the history
(fixed #4557, BP from #4288) プロフィールで『テキスト(複数行)』で『入力値タイプ』が『数値』『メールアドレス』『URL』の場合に改行コードを許容するように変更
  • Loading branch information
nishizoe committed Sep 7, 2022
2 parents 6a564f0 + 7f1e0df commit 46bfcb9
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/util/opFormItemGenerator.class.php
Expand Up @@ -256,7 +256,14 @@ public static function generateValidator($field, $choices = array())
switch ($field['ValueType'])
{
case 'email':
$obj = new sfValidatorEmail($option);
if ('textarea' === $field['FormType'])
{
$obj = new opValidatorMultipleEmail($option);
}
else
{
$obj = new sfValidatorEmail($option);
}
break;
case 'pc_email':
$obj = new opValidatorPCEmail($option);
Expand All @@ -265,14 +272,28 @@ public static function generateValidator($field, $choices = array())
$obj = new sfValidatorMobileEmail($option);
break;
case 'integer':
$obj = new sfValidatorInteger($option);
if ('textarea' === $field['FormType'])
{
$obj = new opValidatorMultipleInteger($option);
}
else
{
$obj = new sfValidatorInteger($option);
}
break;
case 'regexp':
$option['pattern'] = $field['ValueRegexp'];
$obj = new sfValidatorRegex($option);
break;
case 'url':
$obj = new sfValidatorUrl($option);
if ('textarea' === $field['FormType'])
{
$obj = new opValidatorMultipleUrl($option);
}
else
{
$obj = new sfValidatorUrl($option);
}
break;
case 'password':
$obj = new sfValidatorPassword($option);
Expand Down
36 changes: 36 additions & 0 deletions lib/validator/opValidatorMultipleEmail.class.php
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* opValidatorMultipleEmail validates emails.
*
* @package OpenPNE
* @subpackage validator
*/
class opValidatorMultipleEmail extends sfValidatorEmail
{
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
}

public function clean($value)
{
$value = str_replace("\r\n", "\n", $value);
$value = str_replace("\r", "\n", $value);
$values = explode("\n", $value);
foreach ($values as $v)
{
parent::clean($v);
}

return $value;
}
}
36 changes: 36 additions & 0 deletions lib/validator/opValidatorMultipleInteger.class.php
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* opValidatorMultipleInteger validates an integer.
*
* @package OpenPNE
* @subpackage validator
*/
class opValidatorMultipleInteger extends sfValidatorInteger
{
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
}

public function clean($value)
{
$value = str_replace("\r\n", "\n", $value);
$value = str_replace("\r", "\n", $value);
$values = explode("\n", $value);
foreach ($values as $v)
{
parent::clean($v);
}

return $value;
}
}
36 changes: 36 additions & 0 deletions lib/validator/opValidatorMultipleUrl.class.php
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* opValidatorMultipleEmail validates Urls.
*
* @package OpenPNE
* @subpackage validator
*/
class opValidatorMultipleUrl extends sfValidatorUrl
{
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
}

public function clean($value)
{
$value = str_replace("\r\n", "\n", $value);
$value = str_replace("\r", "\n", $value);
$values = explode("\n", $value);
foreach ($values as $v)
{
parent::clean($v);
}

return $value;
}
}

0 comments on commit 46bfcb9

Please sign in to comment.