如何从 Laravel 5.2 中的 textarea 获取价值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40553134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:43:56  来源:igfitidea点击:

How to get value from textarea in Laravel 5.2?

phplaravellaravel-5laravel-5.2

提问by Mr. Pyramid

I'm currently working on Laravel 5.2 and I'm finding difficult to fetch value from textareainside controller.

我目前正在研究 Laravel 5.2,我发现很难从textarea控制器内部获取值。

I've tried $request->inputjust like we used to fetch values from inputs but it's not working in my case. I have done this far.

我已经尝试过$request->input就像我们过去从输入中获取值一样,但在我的情况下它不起作用。我已经做到了这一点。

managecategories.blade.php

managecategories.blade.php

<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
    <div>
        <label>Insert Category</label>
        <input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
    </div>
    <div>
        <label>Insert Category</label>
        <textarea  name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea> 
    </div>
    <input type="submit" value="Add Category" id="category_btn">
</form>

AdminAjaxController

AdminAjaxController

public function addcategory(Request $request)
{
    $category=$request->input('category');
    $category_description=$request->input('description');
    $insertcategory= DB::insert('insert into categories(category_name,description) values(?, ?)',[$category,$category_description]);
    $fetch_category= DB::select('select category_name,category_id from categories');
    return response()->json(array('add_category' => $category),200);
}

采纳答案by Mr. Pyramid

Oops Pity me! Both fields are named category. I need to change the name on the textarea to description caught by Aynber.

哎呀可怜我!这两个字段都被命名为类别。我需要将 textarea 上的名称更改为 Aynber 捕获的描述。

here is the edited and correct code

这是编辑后的正确代码

<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
<div>
    <label>Insert Category</label>
    <input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
</div>
<div>
    <label>Insert Category</label>
    <textarea  name="description" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea> 
</div>
<input type="submit" value="Add Category" id="category_btn">

thanks mate! :)

谢了哥们!:)