0

Here is jQuery code. it works fine at xampp and my server. I would like to add this code into Laravel. Since I post here I recived kind help but still I couldn't get array value at Laravel.

Whole code is here

fiddle

What I tried that I'm guessing this input field has no "name=" so I add name but it can not pass values.

<div class="fieldContainer">
    <div class="btn-group">
      <input type="text" class="search" data-ref="${ref}" placeholder="Type something" class="form-control" onkeypress="return event.keyCode!=13" />
      <span class="search-clear glyphicon glyphicon-remove-circle" data-ref="${ref}"></span>
    </div>
    <ul class="list-group resultUl" data-ref="${ref}"></ul>
    </div>

At xampp or with out Laravel (my server ) I can get array value using below code.

echo var_dump($_POST["search_1"]);

I wrote below code in Laravel. but I'm not sure to how to write in case of multipule array.

now I got error is

Undefined index: search_1

public function register(Request $request)
    {   
       $post_data = $request::all();
       $search_1 = $request::all();
       return view('pn.conf',compact('post_data'),compact('search_1'));
    }

Could someone teach me what is wrong my code please?

1 Answer 1

1

Try to add compact('search_1') to the second argument of the view method:

return view('pn.conf', compact('post_data', 'search_1'));

The third argument of the view method is used to set the status to something else than 200.

You can read the definition here.

Now you can use those variables in your blade view just like this:

{{ $search_1 }}

Take note that $request->all() will return all fields from the request. Use the input() method instead:

$search_1 = $request->input('search_1');

search_1 has to be the name property on the form, or the key in the payload of your json.

Sign up to request clarification or add additional context in comments.

4 Comments

Dear @piscator Thank you very much for answer. I wrote as you teach me but I still got this error. ErrorException (E_ERROR) Undefined index: search_1 what else you could think my problem? I wrote echo var_dump($_POST["search_1"]); at blade file
Dear @piscator Thank you for answering me back then. I've been trying to solve my issue. but still I couldn't find a goal. Could you teach me some advice please?
@machagr: You can check the additions in my answer. Since there is quite some room for improvement in your code it would be a good investment of your time to read a tutorial about jQuery / Ajax / Laravel. Good luck!
Dear @piscator Thank you very much for comment. I fix my code what you told me. but still same... I have one concern. I looked Environment & details In [POST Data] There is no search_1 data. that mean I can't get a search_1 data. Am I right? I can get other all values which are 'post_data' . As I explain first. Without Laravel I can recive search_1 and search_2 data.3 4 5 all value There is no search_1 name or value at Environment & details In [POST Data] . so I already can't recived value ? Can you revice the sear_1 2 3 value using this JS file in Laravel?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.