0

I have a

Create Form

{!! Form::open(array('url' => '/cpe/store', 'class' => 'form-horizontal', 'role' =>'form')) !!}

              <h3 class="nomargin">Create CPE </h3>

              <div class="mb10">
                  <label class="control-label">Account ID </label>
                  <input type="text" class="form-control" name="account_id" value="{{$account->account_id}}">
              </div>

          
              <div class="mb10">
                  <label class="control-label">Max Up</label>
                  <input type="text" class="form-control" name="max_up" value="30000">
              </div>

              <div class="mb10">
                  <label class="control-label">Max Down</label>
                  <input type="text" class="form-control" name="max_down" value="50000" >
              </div>



              <a href="/account/" class="btn btn-danger ">Go back to account </a>

              {!! Form::hidden('$id', $account->account_id )!!}

              <button type="submit" class="btn btn-success ">Create</button>


            {!! Form::close();!!}

Store Function

public function store() {

        $inputs = Input::all();
        unset($inputs['_token']);
      

        $cpe_mac = $inputs['mac1'].$inputs['mac2'].$inputs['mac3'].$inputs['mac4'].$inputs['mac5'].$inputs['mac6'];

        $cpe = [];

        $cpe['cpe_mac'] = $cpe_mac;
        $cpe['bandwidth_max_up'] = (int)$inputs['max_up'];
        $cpe['bandwidth_max_down'] = (int)$inputs['max_down'];

        $json = json_encode($cpe);

        try {

            $url = 'http://172.16.139.129:1234/vse/vcpe';
            $ch = curl_init($url);

            if (FALSE === $ch)
                throw new Exception('failed to initialize');

            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 1);
            $result = curl_exec($ch);
            curl_close($ch);

            if (FALSE === $result)
                throw new Exception(curl_error($ch), curl_errno($ch));

            // ...process $result now
        } catch(Exception $e) {

            trigger_error(sprintf(
                'Curl failed with error #%d: %s',
                $e->getCode(), $e->getMessage()),
                E_USER_ERROR);

        }

        $result_json =  json_decode($result, true);


        dd($id); // Undefined variable: id


        if ( $result_json['status'] == '200') {
            return Redirect::to('/account/'.$id.'#hardware') ->with('success','The CPE was created succesfully!');
        } else {
            return Redirect::to('/account/'.$id.'#hardware') ->with('error', $result_json['message']);
        }

    }

I'm trying to pass {!! Form::hidden('$id', $account->account_id )!!} to my store controller so I can access it inside my store() function in my controller.

But I keep getting Undefined variable: id

Can someone please show me the proper way of sending a hidden input from a form to a controller ?

3
  • You haven't shown us the code in your controller's store method. Commented Nov 16, 2015 at 23:46
  • 1
    The id is in $inputs['id'] Commented Nov 17, 2015 at 0:13
  • It works perfectly. You should answer it. I will accept it. :) Commented Nov 17, 2015 at 0:18

1 Answer 1

2

There are two things wrong with your code:

  1. Your hidden input should use id, not $id.
  2. Your store method should use $inputs['id'], not access $id directly.
Sign up to request clarification or add additional context in comments.

Comments

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.