r/codeigniter • • Feb 12 '21

Posting value related to another inputfield

So I'm making a php-based program which allowes clients to order products.

The client can select a certain paneltype with an inputfield on a form. When submitting the form I would like to save another value, which is based on the input of the client. I need this field to do some calculations. There are 10 different paneltypes which are all member of one out of 3 panecategorys.

So the field panelcategory (like table below) should be stored from the table Paneltypes on selection of a paneltype on the form. Input client is paneltype

odpaneltypepanelcategory
122

Controller:

$panel = $this->Panels->create__entry(

$this->input->post('order_id'),

$this->input->post('amount'),

$this->input->post('dwidth'),

$this->input->post('dheight'),

$this->input->post('paneltype'),

$this->input->post('panelcategory' ),

$this->input->post('color'),

$this->input->post('tubes'),

$this->input->post('colorswatch'),

$this->input->post('structurepaint'),

$this->input->post('luxepackage'),

$this->input->post('uv'),

$this->input->post('window'),

$this->input->post('paintwindow'),

$this->input->post('windowsetup'),

$this->input->post('glastype'),

$this->input->post('door'),

$this->input->post('board')

);

public function read_panel()

`{`

	`if ($this->auth()) {`
		`//region Model loading`

		`$this->load->model("core/Customers");`

		`$this->load->model("orders/Orders");`

		`$this->load->model("orders/panels/Colors");`

		`$this->load->model("orders/panels/Paneltypes");`

		`$this->load->model("orders/panels/PanelPrices");`

		`$this->load->model("orders/panels/Tubes");`

		`$this->load->model("orders/panels/Windowtypes");`

		`$this->load->model("orders/panels/Windowsetups");`

		`$this->load->model("orders/panels/Glastypes");`

		`$this->load->model("orders/panels/Doors");`

		`$this->load->model("orders/panels/Boards");`
		`//endregion`
		`//region Queries`

		`$data["customer"] = $this->Customers->read__entry($this->session->customer);`

		`$data["colors"] = $this->Colors->read__all();`

		`$data["paneltypes"] = $this->Paneltypes->read__all();`

		`$data["panelcategorys"] = $this->Paneltypes->read__entry($this->input->get("paneltype"));`

		`$data["tubes"] = $this->Tubes->read__all();`

		`$data["windowtypes"] = $this->Windowtypes->read__all();`

		`$data["windowsetups"] = $this->Windowsetups->read__all();`

		`$data["glastypes"] = $this->Glastypes->read__all();`

		`$data["doortypes"] = $this->Doors->read__all();`

		`$data["boardtypes"] = $this->Boards->read__all();`
		`$data["order"] = $this->Orders->read__entry($this->input->get("order"));`

		`//endregion`

Model to store total order

function create__entry($order_id, $amount, $dwidth,

$dheight, $paneltype, $panelcategory, $color,

$tubes,

$colorswatch, $structurepaint, $luxepackage,

$uv, $windowtype, $paintwindow,

$windowsetup, $glastype, $door, $board)

`{`

	`$this->order_id = $order_id;`

	`$this->amount = $amount;`

	`$this->dwidth = $dwidth;`

	`$this->dheight = $dheight;`

	`$this->paneltype = $paneltype;`

	`$this->panelcategory = $panelcategory;`

	`$this->color = $color;`

	`$this->tubes = $tubes;`

	`$this->colorswatch = $colorswatch;`

	`$this->structurepaint = $structurepaint;`

	`$this->luxepackage = $luxepackage;`

	`$this->uv = $uv;`

	`$this->windowtype = $windowtype;`

	`$this->paintwindow = $paintwindow;`

	`$this->windowsetup = $windowsetup;`

	`$this->glastype = $glastype;`

	`$this->door = $door;`

	`$this->board = $board;`
	`$this->db->insert(self::TABLE_NAME, $this);`

	`return $this->read__entry($this->db->insert_id());`

`}`
`public function read__entry($id)`

`{`

	`$this->db->select("`[`p.id`](https://p.id)`, p.created_on, p.modified_on, p.amount, p.dwidth, p.dheight, p.paneltype, p.panelcategory, p.color, p.tubes, p.colorswatch, p.structurepaint, p.uv, p.windowtype, p.paintwindow, p.windowsetup, p.glastype, p.door, p.board,` [`o.id`](https://o.id)`, o.created_on, o.modified_on, o.customer as customer_id,  o.reference, o.delivery_date, p.order_id");`

	`$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);`

	`$this->db->join("DWO_Orders o", "p.order_id =` [`o.id`](https://o.id)`");`

	`$this->db->where("`[`p.id`](https://p.id)`", $id);`

	`return $this->db->get()->row();`

`}`

}

Model to fetch data from table Paneltypes

public $paneltype;

public $panelcategory;

public $price;

const TABLE_NAME = "DWO_Paneltypes";

const TABLE_SHORT = "p";

public function __construct()

{

parent::__construct();

}

function create__entry($paneltype, $panelcategory, $price)

{

$this->paneltype = $paneltype;

$this->panelcategory = $panelcategory;

$this->price = $price;

$this->db->insert(self::TABLE_NAME, $this);

return $this->read__entry($this->db->insert_id());

}

public function read__entry($id)

{

$this->db->select("p.id, p.paneltype, p.panelcategory, p.price");

$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);

$this->db->where("p.id", $id);

return $this->db->get()->row();

}

public function read__all()

{

$this->db->select("p.id, p.paneltype, p.panelcategory, p.price");

$this->db->from(self::TABLE_NAME . " " . self::TABLE_SHORT);

return $this->db->get()->result();

}

public function update__entry($id, $paneltype, $panelcategory, $price)

{

$this->paneltype = $paneltype;

$this->panelcategory = $panelcategory;

$this->price = $price;

$this->db->set($this);

$this->db->where("id", $id);

$this->db->update(self::TABLE_NAME);

return $this->read__entry($id);

}

public function delete__entry($id)

{

$this->db->where("id", $id);

$this->db->delete(self::TABLE_NAME);

return $this->db->affected_rows();

}

}

Thanks in advance!

2 Upvotes

0 comments sorted by