[英]Limit number of characters in input field with PHP
我正在使用此WordPress插件創建人員數據庫。 在注冊表單上,我想限制用戶可以在某些字段中輸入的字符數,但是我不知道怎么做,因為我不是程序員,並且對PHP和Javascript的了解有限。 由於使用的是插件,因此無法直接編輯HTML,因此不能僅使用maxlength HTML屬性。 注冊頁面基於插件中的以下PHP模板,所以我想這就是我需要編輯的內容,但是如何編輯?
<?php
/*
* bootstrap template for signup form
*
* outputs a Twitter Bootstrap-compatible form
* http://twitter.github.com/bootstrap/index.html
*
*/
?>
<div class="wrap <?php echo $this->wrap_class ?>" >
<?php // this is how the html wrapper for the error messages can be customized
$this->print_errors( '<div class="alert %1$s">%2$s</div>','<p>%s</p>' ); ?>
<?php $this->print_form_head(); // this must be included before any fields are output ?>
<div class="form-horizontal pdb-signup">
<?php while ( $this->have_groups() ) : $this->the_group(); ?>
<fieldset class="field-group field-group-<?php echo $this->group->name ?>">
<?php $this->group->print_title( '<legend>', '</legend>' ) ?>
<?php $this->group->print_description() ?>
<?php while ( $this->have_fields() ) : $this->the_field(); ?>
<?php $feedback_class = $this->field->has_error() ? 'error' : ''; ?>
<div class="<?php $this->field->print_element_class() ?> control-group <?php echo $feedback_class ?>">
<label class="control-label" for="<?php $this->field->print_element_id() ?>" ><?php $this->field->print_label(); // this function adds the required marker ?></label>
<div class="controls"><?php $this->field->print_element_with_id(); ?>
<?php if ( $this->field->has_help_text() ) :?>
<span class="help-block">
<?php $this->field->print_help_text() ?>
</span>
<?php endif ?>
</div>
</div>
<?php endwhile; // fields ?>
</fieldset>
<?php endwhile; // groups ?>
<fieldset class="field-group field-group-submit">
<div id="submit-button" class="controls">
<?php $this->print_submit_button('btn btn-primary'); // you can specify a class for the button ?>
<span class="pdb-retrieve-link"><?php $this->print_retrieve_link(__('Forget your private link? Click here to have it emailed to you.','participants-database')); ?></span>
</div>
</fieldset>
</div>
<?php $this->print_form_close() ?>
</div>
找出您輸入字段的ID,然后將以下腳本添加到文件中。
<script type="text/javascript">
window.onload = function() {
jQuery('#input_field_id').attr('maxlength','100');
}
</script>
像這樣使用strlen()
:
<?php
session_start();
$Text = html_specialchars($_POST['Input_1']);
$Text_max = 100; //characters for max input
if(strlen($Text)>$Text_max){
//$Text has more than 100 characters (including spaces!)
}
else{
//Do your thing
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.