Php 如何在Laravel Livewire中传递隐藏表单输入?
最近,我一直在尝试实现laravel的livewire,以提交表单并刷新页面,而不实际使用当代基于ajax的流。除了我需要发送一些隐藏的输入值,在提交表单之前,我会根据用户的操作来更改这些值之外,它对任何事情都适用Php 如何在Laravel Livewire中传递隐藏表单输入?,php,jquery,laravel,web,laravel-livewire,Php,Jquery,Laravel,Web,Laravel Livewire,最近,我一直在尝试实现laravel的livewire,以提交表单并刷新页面,而不实际使用当代基于ajax的流。除了我需要发送一些隐藏的输入值,在提交表单之前,我会根据用户的操作来更改这些值之外,它对任何事情都适用 <input type="text" class="w-100 ratings-hidden" value="" wire:model="rating_val"> <input clas
<input type="text" class="w-100 ratings-hidden" value="" wire:model="rating_val">
<input class="" value="" wire:model="reviewable_id" type="hidden">
<textarea class="form-control w-100 animated" cols="50" id="new-review" wire:model="comment" placeholder="Enter your review here..." rows="5"></textarea>
在这里,提交后很好地获取了评论,但我无法获取rating_val和reviewable_id的值,请从输入中删除value=“”,因为livewire为您提供了这一功能
在组件中设置属性,需要($rating\u val,$reviewable\u id),在mount方法中初始化这些属性的值
class ComponentName extends Component
{
public $rating_val;
public $reviewable_id;
public function mount()
{
$this->rating_val = "value_for_input";
$this->reviewable_id = "value_for_input";
}
}
在刀片文件中,您只需要以下内容
<input type="hidden" wire:model="rating_val">
<input type="hidden" wire:model="reviewable_id">
从输入中删除value=”“,因为livewire会为您执行此操作
在组件中设置属性,需要($rating\u val,$reviewable\u id),在mount方法中初始化这些属性的值
class ComponentName extends Component
{
public $rating_val;
public $reviewable_id;
public function mount()
{
$this->rating_val = "value_for_input";
$this->reviewable_id = "value_for_input";
}
}
在刀片文件中,您只需要以下内容
<input type="hidden" wire:model="rating_val">
<input type="hidden" wire:model="reviewable_id">
您可能不需要隐藏输入,您可能只需要在组件上拥有一个属性,并通过用户操作来维护它。然后,不要设置隐藏输入的值,只需执行
$set('reviewable_id','someValue')
(当然取决于您如何设置它,这里没有显示)。谢谢,这对我有用您可能不需要隐藏输入,您可能只需要在组件上拥有一个属性,并通过用户操作来维护它。然后,不要设置隐藏输入的值,只需执行$set('reviewable_id','someValue')
(当然取决于您如何设置它,这里没有显示)。谢谢,这对我有用