允许文本字段中包含特殊字符

时间:2017-01-27 02:31:17

标签: php html yii character

我正在尝试修改一个不允许特殊字符允许的输入字段。这是我正在使用的代码片段。

<div class="form-group">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('class'=>'form-control','onkeyup'=> 'return IsAlphaNumeric(event)')); ?>
<?php echo $form->error($model,'name'); ?>
</div>

似乎中间的PHP行是导致它阻止特殊字符的那一行我只是不知道如何编辑它以允许特殊字符。

以下是我正在处理的文件中的完整代码:

<?php
/* @var $this CategoriesController */
/* @var $model Categories */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'categories-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
 'enableAjaxValidation'=>true,
 'htmlOptions' => array('enctype' => 'multipart/form-data','onsubmit'=> 'return validateCategory()'),
)); ?>

    <p class="note">
    <?php echo Yii::t('admin' , 'Fields with'); ?>
        <span class="required"> * </span>
        <?php echo Yii::t('admin', 'are required.'); ?>
    </p>

    <?php //echo $form->errorSummary($model); ?>

    <div class="form-group">
    <?php echo $form->labelEx($model,'name'); ?>
    <?php echo $form->textField($model,'name',array('class'=>'form-control','onkeyup'=> 'return IsAlphaNumeric(event)')); ?>
    <?php echo $form->error($model,'name'); ?>
    </div>

    <div class="form-group">
    <?php echo $form->labelEx($model,'parentCategory'); ?>
    <?php //echo $form->textField($model,'parentCategory'); ?>
    <?php if (!empty($parentCategory)){
        echo $form->dropDownList($model, 'parentCategory', $parentCategory, array('empty'=>Yii::t('admin','Select Parent category'),'id'=>'dropCat','onchange'=>'return dropCategory()','class'=>'form-control'));
    }else{
        echo $form->dropDownList($model, 'parentCategory', array(''=>Yii::t('admin','Select Parent category')), array('id'=>'dropCat','onchange'=>'return dropCategory()','class'=>'form-control'));
    }
    ?>
    <?php echo $form->error($model,'parentCategory'); ?>
        <p><?php echo Yii::t('admin','Note: To create Parent Category,Leave this drop down Empty.'); ?></p>
    </div>

<?php if(isset($model->parentCategory) && $model->parentCategory == 0 || !isset($model->parentCategory)) { ?>
    <div class="checkbox checkbox-custom " id="itemCondition">
    <?php 

    echo $form->checkBox($model, 'itemCondition', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'itemCondition');
    ?>
    </div>
    <?php
    $sitepaymentmodes = Myclass::getSitePaymentModes();
    if($sitepaymentmodes['exchangePaymentMode'] == "1")
    {
    ?>
    <div class="checkbox checkbox-custom" id="exchangetoBuy">
    <?php 

    echo $form->checkBox($model, 'exchangetoBuy', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'exchangetoBuy');
    ?>
    </div>
    <?php
    }
    if($sitepaymentmodes['buynowPaymentMode'] == "1")
    {
    ?>
    <div class="checkbox checkbox-custom" id="buyNow">
    <?php 

    echo $form->checkBox($model, 'buyNow', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'buyNow');
    ?>
    </div>
    <?php
    }   
    ?>

    <div class="checkbox checkbox-custom" id="myOffer">
    <?php 

    echo $form->checkBox($model, 'myOffer', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'myOffer');
    ?>
    </div>
    <?php } else { ?>
    <div class="checkbox checkbox-custom " id="itemCondition" style='display:none;'>
    <?php 

    echo $form->checkBox($model, 'itemCondition', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'itemCondition');
    ?>
    </div>
    <?php
    $sitepaymentmodes = Myclass::getSitePaymentModes();
    if($sitepaymentmodes['exchangePaymentMode'] == "1")
    {
    ?>
    <div class="checkbox checkbox-custom" id="exchangetoBuy" style='display:none;'>
    <?php 

    echo $form->checkBox($model, 'exchangetoBuy', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'exchangetoBuy');
    ?>
    </div>
    <?php
    }
    if($sitepaymentmodes['buynowPaymentMode'] == "1")
    {
    ?>
    <div class="checkbox checkbox-custom" id="buyNow" style='display:none;'>
    <?php 

    echo $form->checkBox($model, 'buyNow', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'buyNow');
    ?>
    </div>
    <?php
    }   
    ?>

    <div class="checkbox checkbox-custom" id="myOffer" style='display:none;'>
    <?php 

    echo $form->checkBox($model, 'myOffer', array('value'=>1, 'uncheckValue'=>0));
    echo $form->labelEx($model,'myOffer');
    ?>
    </div>
    <?php } ?>  
    <!--div class="checkbox checkbox-custom" id="contactSeller">
    <?php 
    echo $form->labelEx($model,'contactSeller');
    echo $form->checkBox($model, 'contactSeller', array('value'=>1, 'uncheckValue'=>0));
    ?>
    </div-->

    <div class="form-group">
    <?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('admin','Create') : Yii::t('admin','Save'),array('class' => 'btn btn-success')); ?>
    </div>

    <?php $this->endWidget(); ?>

</div>
<!-- form -->
<script>
    $("#catImage").show();
    if ($("#dropCat").val() != "") {
        $("#catImage").hide();
    } else {
        $("#catImage").show();
    }
</script>

2 个答案:

答案 0 :(得分:0)

此功能仅允许AlphaNumeric(字母,数字和空格)。

'return IsAlphaNumeric(event)'

答案 1 :(得分:0)

删除<?php echo $form->textField($model,'name',array('class'=>'form-control')); ?> 例如

public static DbContext GetDbContextFromEntity(object entity)
{
    var object_context = GetObjectContextFromEntity( entity );

    if ( object_context == null )
        return null;

    return new DbContext( object_context, dbContextOwnsObjectContext: false );
}

private static ObjectContext GetObjectContextFromEntity(object entity)
{
    var field = entity.GetType().GetField("_entityWrapper");

    if ( field == null )
        return null;

    var wrapper  = field.GetValue(entity);
    var property = wrapper.GetType().GetProperty("Context");
    var context  = (ObjectContext)property.GetValue(wrapper, null);

    return context;
}