0

I'm trying to use the plugin to show all nationalities on front-end form, I'm able to pull the countries, but I'm unable to get the selected option by the client to be saved on the DB. When trying to access the data on the back-end forms I get errors. (The model class Lindelwa\EBilitiesResearch\Models\Application must define a method getCountryIdOptions() returning options for the 'country_id' form field.)

I've tried to make sense of what's in the documentation:

http://octobercms.com/docs/backend/forms#field-dependencies

But I've failed.

Here's an image of what I'm trying to achieve. enter image description here

Error I get When trying to edit back-end form entry

Model class

I want to be able to show countries in a drop-down List on the front-end and when to accessed on the back-end I should be able to check which country has been selected and still show all countries in a drop-down list.

Lindelwa
  • 27
  • 6

1 Answers1

0

Ok, if you want to show dropdown in backend form , first of all you need list/data to display in drop down then only selected value will be set,

to fill values in drop-down you need to provide method, your field name is country_id so you already added getCounteryIdOptions() so just you need to return array from it.

public function getCounteryIdOptions() {
    // you fetch all records / same way as in frontend you are showing
    // format value/id => title

    $result = [];
    // foreach loop
    $result[$record->id] = $record->title;
    // $result[1] = 'Xyz Country';
    // for loop end
    return $result;
}

so it will return all the country list now this will be added to dropdown and selected value which is selected by user is shown selected

if its not working please comment.

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40