0
votes

I need a dynamic form, which is created depending on database entries. To input the data into the database, this also needs to be dynamic. For some reason I am getting null in the value of my form.

My form loop

@foreach ($keyAccounts as $keyAccount)
        {{ Form::label($keyAccount->name, $keyAccount->name.':', array('class' => '')) }}
        {{ Form::text($keyAccount->name)}}<br />
    @endforeach

which returns

<label for="hsbc dad" class="">hsbc dad:</label>
        <input name="hsbc dad" type="text" id="hsbc dad"><br />
                <label for="sdsad" class="">sdsad:</label>
        <input name="sdsad" type="text" id="sdsad"><br />
                <label for="dfffff" class="">dfffff:</label>
        <input name="dfffff" type="text" id="dfffff"><br />

When my form is submitted it calls on the actions controller and runs the following code

foreach($keyAccounts as $keyAccount){
        $assignedAccount = new AssignedAccount;
        $assignedAccount->contribution_id = $last_con_id->contribution_id;
        $assignedAccount->key_account_id = $keyAccount->key_account_id; 
        $assignedAccount->year_to_date = Input::get($keyAccount->name);
        $assignedAccount->save();
    }

I am getting the year_to_date variable is null in an SQL error, even though the data is filled out.

here is my var_dump of the Input::get()

NULL string(1) "3" string(1) "3"

I don;t know why but the first entry is null. There is a total of three entries in the database, and no name variable is null

1

1 Answers

2
votes

Automated conversion to underscores where the space character is present. Remove the space character or convert to underscore. Try Input::get('hsbc_dad')

Heres another example