I am using wordpress 4.1 along with WP MVC.
I have 3 three tables that need to be added with a single form input.
Tables: (prefix for all tables: ‘wp_w2store_’): manufacturers, addresses, countries, zones.
When I choose to add a ‘Manufacturer’, i need to add the fields of address table in the same form and along with that i have to retrieve country_name and zone_name from the respective tables, which are also form the fields list of ‘Address’.
I dont even get the form inputs in the form and i get this error:
MVC Fatal Error: Field “user_id” not found for use in a form input.
since ‘user_id’ is the first foreign field to this form, it alone is shown here. if i remove that field, the error will be shifted to next available field and so on.
In the add() function of admin_manufacturers_controller, i have loaded the model ‘Address’ and set that with all its fields in an array variable, $addresses, as follows:
public function add() {
$this->set_manufacturers();
$this->set_addresses();
$this->create_or_save();
}
private function set_addresses() {
$this->load_model('Address');
$addresses = $this->Address->find(array('selects' => array('id', 'user_id', 'first_name', 'last_name',
'address_1', 'address_2', 'email', 'city', 'zip', 'zone_id', 'country_id',
'phone_1', 'phone_2', 'fax', 'type', 'company', 'tax_number', 'customer_note')));
$this->set('addresses', $addresses);
}
and this is the add.php of manufacturers:
input fields for manufacturers table:
<?php echo $this->form->create($model->name); ?>
<?php echo $this->form->belongs_to_dropdown('Address', $addresses, array('style' => 'width: 200px;', 'empty' => true)); ?>
<?php echo $this->form->input('enabled');?>
<?php echo $this->form->input('ordering');?>
input fields for address table:
<h4>Address Fields</h4>
<?php echo $this->form->input('Address.user_id');?>
<?php echo $this->form->input('Address.first_name');?>
<?php echo $this->form->input('Address.last_name');?>
<?php echo $this->form->input('Address.email');?>
<?php echo $this->form->input('Address.address_1');?>
<?php echo $this->form->input('Address.address_2');?>
and so on…
Since I dont have enough reputation, i dont have privilege to add an image in the question. Kindly bear.
Any suggestions to rectify this issue is thankfully welcome.
This issue is solved by adding the code below to the manufacturer model for joining the tables:
Thanks.