2

I have the following code:

In my view:

{{Form::open()}}
{{Form::hidden ('hiddentitle', 'title info')}}
{{Form::close()}}

In my controller:

  class PController extends BaseController {

   public function user(){

  $hiddentitle               = Input::get('hiddentitle');


  dd($hiddentitle); //I get NULL values      

  return View::make('person.user');

    }

   }

Can anyone explain why I get NULL values for $hiddentitle? I know this seems very simple but it's a big problem. Thanks

8
  • You made sure the title existed, but does it have a user_id = 3? Commented Jun 1, 2015 at 16:56
  • It definitely does have a user_id of 3 Commented Jun 1, 2015 at 16:59
  • Looks right to me. What do you get with dd($hiddentitle); and separately dd($checktitle); ? Commented Jun 1, 2015 at 16:59
  • I get NULL when I check $hiddentitle which is strange hmm Commented Jun 1, 2015 at 17:04
  • Can you show your whole form and controller function? Commented Jun 1, 2015 at 17:06

1 Answer 1

-1

How are you submitting the form?

I just tested this code and it works for me with Laravel 5.

routes.php

Route::resource('test', 'TestController');

Controller

public function create()
{
    return view('test.create');
}

public function store()
{
    dd(\Input::get('hiddentitle'));
}

test/create.blade.php

{!! Form::open() !!}
{!! Form::hidden ('hiddentitle', 'title info')!!}
{!! Form::submit('Go') !!}
{!! Form::close() !!}

results

"title info"

Edited per comments

I am unclear on exactly what you are trying to do. If you post your attempts I could answer your question better. I believe you would like to do something like this.

@foreach ($user->books as $book)

    @if(!emtpy($book->title)
        {!! Form::open() !!}
        {!! Form::hidden ('hiddentitle', 'title info')!!}
        {!! Form::submit('Go') !!}
        {!! Form::close() !!}
    @endif

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

6 Comments

I dont want to submit the form I just want to access the value
@Billy at what point are you trying to access the value? If you don't submit the form the value won't go to the controller. The Controller sets the View variables and the View sends those variables back to the Controller on submit. If you are setting the hiddentitle from your user function you would do something like return view('person.user')->with('hiddentitle', 'title info');
ahh i see. I want to validate whether show a form depending on the looped info in the view. Any ideas on how to validate only parts of looped data?
I mistakenly edited the question to make it easier but I'll just repost another question but in summary I want to execute this query in my controller. $check = Model::where('user_id', 3)->where ('title', $hiddentitle)->first(); and then in my view use the isset method to display my form or not.
@Billy Where are you setting $hiddentitle?
|

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.