Forloop through input's and retrieve the value

时间:2017-08-30 20:09:52

标签: php html arrays forms laravel

i have this problem:

When i forloop through 50 input's and i only filled in the first input the request / post returns function checkWin(){ let emptyword =["h,","e,","l,","l","o"] let computerword= "hello"; var a = emptyword.join(""); let b = computerword.toString(); let c = a.toString(); console.log("computerword :" + b); console.log("emptyword is:" + c ); if(b === c) { console.log("someone has won"); } else if ( b != c) { console.log("b is not same as c"); } } checkWin(). But when i fill in the last input it returns the value.

Controller code

hello

And this is the form

hello

3 个答案:

答案 0 :(得分:2)

Your input name is not correct. If you want to have multiple inputs with same name, you have declare it as an array.

In Html Replace

term

with

terms

In your controller

Loop the input array and add code to insert it to database.

$producttype = $_GET['ProductType'];
$businessunit = $_GET['BusinessUnit'];
$products = new WP_Query( array( 
  'post_type' => 'products',
  'posts_per_page' => 15,
  'orderby' => 'title',
  'order'   => 'ASC',
  'paged' => $paged,
  'tax_query' => array(
    'relation' => 'OR',
     array(
       'taxonomy' => 'producttype',
       'field' => 'name',
       'terms' => $producttype
     ),
     array(
       'taxonomy' => 'businessunit',
       'field' => 'name',
       'terms' => $businessunit
     )
  )

答案 1 :(得分:2)

It's hard to understand what are you trying to achieve but:

component

This is your form. Set indexes in <HashRouter> <Switch> <Route exact path="/" component={Home} /> <Route exact path="/about" component={About} /> <Route path="/rlogin" render={() => ( <div> <Header /> <ReceiverLoginForm /> <Footer /> </div> ) /> {/* Do the same for the routes that you want the Header & Footer on */} </Switch> </HashRouter> attribute explicitly. In this case your func write(image overlayImage:UIImage, toBuffer sample:CMSampleBuffer){ let pixelBuffer = CMSampleBufferGetImageBuffer(sample) CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) var bitmapInfo: UInt32 = CGBitmapInfo.byteOrder32Little.rawValue bitmapInfo |= CGImageAlphaInfo.premultipliedFirst.rawValue & CGBitmapInfo.alphaInfoMask.rawValue let context = CGContext(data: CVPixelBufferGetBaseAddress(pixelBuffer!), width: CVPixelBufferGetWidth(pixelBuffer!), height: CVPixelBufferGetHeight(pixelBuffer!), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: bitmapInfo) context?.draw(overlayImage.cgImage!, in: CGRect(x: 0.0, y: 0.0, width: overlayImage.size.width, height: overlayImage.size.height)) CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) } will look like:

<form action="/form" method="post">
    {{csrf_field()}}
    @for($x = 0; $x++ < 50;)
        <input type="text" name="type[{{$x}}][id]">
        <input type="text" name="type[{{$x}}][name]">
    @endfor

    <button type="submit">Submit</button>
</form>

In controller you can iterate over it:

name

答案 2 :(得分:0)

好的,所以我把@ravinder和@u_mulder的答案结合起来。这个解决方案对我有用。

表格:

<form action="/form" method="post">
{{csrf_field()}}
@for($x = 0; $x++ < 50;)
    <input type="text" name="type[{{$x}}][id]">
    <input type="text" name="type[{{$x}}][name]">
@endfor
<button type="submit">Submit</button>

控制器

    public function store(Request $request)
{

    foreach ($request->type as $value) {
        if(!empty($value['id']) && !empty($value['name'])) { // if they are not empty proceed
            $country = Country::create([ // Create a country
                'user_id' => $value['id'],
                'country' => $value['name'],
            ]);
        }
    }
}

感谢帮助人员!