' htmlentities()期望参数1为字符串,给定数组' Laravel视图出错

时间:2016-10-06 13:48:40

标签: laravel laravel-5 laravel-5.2

我正在测试我的创建视图的Request.php(提交带有空必填字段的表单),并得到' htmlentities()期望参数1为字符串,数组给定'错误。

我知道错误是由于下面的代码而生成的。这是我的视图(调用javascript函数)的一部分,用于创建将来的约会提醒。

我只是不知道究竟是什么导致了错误。

<div style="display:none">    
<div id="reminderiteminitial">      
<div class="row" style="padding: 0.5em 0 0.5em 0.5em">  
      <div class="col-sm-2" >
           {!! Form::text('reminder_time[]', 30, ['class' => 'form-control', 'placeholder' => '']) !!}
      </div>
      <div class="col-sm-2" >
           {!! Form::select('reminder_timeunit[]', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control']) !!}
      </div>
      <div class="col-sm-2" >
           {!! Form::select('delivery_method[]', ['eml' => 'Email'], null, ['class' => 'form-control']) !!}
      </div>
      <div class="col-sm-4" >
           {!! Form::text('delivery_contact[]', null, ['class' => 'form-control', 'placeholder' => 'Your email address']) !!}
      </div>
      <div class="col-sm-2" >
          <input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
      </div>

</div>
</div>
</div>

<div id="reminderitem">     
</div>

<div class="row" style="padding: 1.5em 0 2.5em 0">      
<div class="col-sm-12">         
      <input class="btn btn-default" type="button" value="Add a reminder" onClick="addreminderitem();">
</div>
</div>  

使用Javascript:

<script language='javascript' type='text/javascript'>

  var itemCount = 1;
  var limit     = 6;

  function addreminderitem(){

        if (itemCount == limit)  {

           alert("You have reached the maximum number of reminders.");
        }
        else  {
           var newreminderitem            = document.getElementById('reminderitem');
           var initialreminderitem_clone  = document.getElementById('reminderiteminitial').cloneNode(true);

           initialreminderitem_clone.id   = 'item_'+itemCount++;

           newreminderitem.appendChild(initialreminderitem_clone);
        }
  } 

  function removeitem(item){
        item.parentNode.parentNode.parentNode.remove(); 

        itemCount = itemCount - 1;
  }     

</script>

哎呀表演:

reminder_time   
array:1 [
  0 => "30"
]

reminder_timeunit 
array:1 [
  0 => "minute"
]

delivery_method 
array:1 [
  0 => "eml"
]

delivery_contact 
array:1 [
  0 => ""
]

更新#2

如果我替换以下HTML表单代码,那么奇怪的是:

  <div class="col-sm-2" >
       {!! Form::text('reminder_time[]', 30, ['class' => 'form-control', 'placeholder' => '']) !!}
  </div>
  <div class="col-sm-2" >
       {!! Form::select('reminder_timeunit[]', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control']) !!}
  </div>
  <div class="col-sm-2" >
       {!! Form::select('delivery_method[]', ['eml' => 'Email'], null, ['class' => 'form-control']) !!}
  </div>
  <div class="col-sm-4" >
       {!! Form::text('delivery_contact[]', null, ['class' => 'form-control', 'placeholder' => 'Your email address']) !!}
  </div>
  <div class="col-sm-2" >
      <input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
  </div>

使用它生成的html:

<div class="col-sm-2" >
   <input class="form-control" placeholder="" name="reminder_time[]" type="text" value="30">
</div>
<div class="col-sm-2" >
   <select class="form-control" name="reminder_timeunit[]"><option value="minute">minutes(s)</option><option value="hour">hour(s)</option><option value="day">day(s)</option><option value="week">week(s)</option><option value="month">month(s)</option></select>
</div>
<div class="col-sm-2" >
   <select class="form-control" name="delivery_method[]"><option value="eml">Email</option></select>
</div>
<div class="col-sm-4" >
   <input class="form-control" placeholder="Your email address" name="delivery_contact[]" type="text">
</div>
<div class="col-sm-2" >
  <input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
</div>

我没有收到错误!?

1 个答案:

答案 0 :(得分:0)

Erorr

您的字段名称必须声明为字符串而不是数组:

procedure TServerForm.FormCreate(Sender: TObject);
var
  ServerSSLIOHandler: TIdServerIOHandlerSSLOpenSSL;
  rootdir           : string;
begin
  inherited;

  rootdir:=ExtractFilePath(Application.ExeName);

  ServerSSLIOHandler:=TIdServerIOHandlerSSLOpenSSL.Create(self);
  ServerSSLIOhandler.SSLOptions.RootCertFile:=rootdir+'ca.cert.pem';
  ServerSSLIOhandler.SSLOptions.CertFile:=rootdir+'localhost.cert.pem';
  ServerSSLIOhandler.SSLOptions.KeyFile:=rootdir+'localhost.key.pem';
  ServerSSLIOhandler.SSLOptions.Method:=sslvSSLv23;
  ServerSSLIOhandler.SSLOptions.Mode:=sslmServer;
  ServerSSLIOhandler.OnGetPassword:=NIL;
  ServerSSLIOhandler.OnVerifyPeer:=OnVerifyPeer;

  HTTPServer:=TIdHTTPServer.Create(self);
  HTTPServer.IOhandler:=ServerSSLIOHandler;
  HTTPserver.Bindings.Add.Port:=443;
  HTTPserver.Bindings.Add.Port:=8080;
  HTTPServer.Active:=True;
  HTTPServer.AutoStartSession:=True;
  HTTPServer.SessionTimeOut:=1200000;
  HTTPserver.OnQuerySSLPort:=OnQuerySSLPort;
  HTTPServer.OnCommandGet:=HTTPServerCommandGet;
  ...
end;

procedure TServerForm.OnQuerySSLPort(APort: Word; var VUseSSL: Boolean);
// This will not be called when the request is a HTTPS request
// It facilitates the use of the server for testing via HTTP://localhost:8080 (i.e. without SSL)
begin
  VUseSSL := (APort<>8080);
end;

function TServerForm.OnVerifyPeer(Certificate: TIdX509; AOk: Boolean; ADepth, AError: Integer): Boolean;
begin
  result:=AOk;
end;

而不是

<input name="reminder_time" /> 

验证数组

或者您可以更改数组(https://laravel.com/docs/5.3/validation#validating-arrays)的验证规则:

<input name="reminder_time[]">`