Insert datas to db via the backend (form.php)

  • Posts: 39
  • Thank you received: 0
11 years 7 months ago #96829

Hello Everybody,

I wanted to add some extra options in the backend when creating/editing a product (availability for 3 kinds of conditions (new, used etc).
I added 3 checkboxes in the form.php file (administrator/com_hikashop/views/product/...) and now wanted to insert a boolean to the database if the checkbox was selected (=1) or not (=0).
I already created 3 columns in jos_hikashop_product, but I need the file or the function which inserts/updates the data to the database after clicking on "Save" in the backend.

It would be great if someone could help me with that one,
greetings,
David

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 7 months ago #96855

Hi,

You should just set an input name like that: data[product][column_name]
where column name is the name of the column in the product table in the database and then the system will handle the field automatically without you doing anything.

Otherwise, you're lookinf for the function saveForm of the file administrator/components/com_hikashop/classes/product.php

Please Log in or Create an account to join the conversation.

  • Posts: 39
  • Thank you received: 0
11 years 7 months ago #96985

Okay I will try it with the data[product]...
But what does it exactly do? In form.php there are a few lines e.g

$this->product_name_input = "data[product][product_name]";
$this->product_url_input = "data[product][product_url]";

It would be great if someone could explain how it works and what happens to the $this->product.. Variables.

How do I set it?
In the form itself it looks like this:
<div class="availability"><u>Verf&uuml;gbarkeit</u><br /><br  />
     <input type="checkbox" name ="nl" value="newlabel" /> Neu, versiegelt <br />
     <input type="checkbox" name ="n"  value="newopened" /> Neu, in offener Originalverpackung <br />
     <input type="checkbox" name ="u"  value="used" /> Gebraucht <br />
</div>

I know that there is no form-tag, I wanted to ask how to combine this form with the saveform()-function as the trigger.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 7 months ago #97069

The form tag is in the "form" view file.
Suppose that you have a text input, it should be:

<input type="text" name ="data[product][column_name]"  value="<?php echo @$this->element->column_name; ?>" />
and the rest will be automatic.

The following user(s) said Thank You: Storm15

Please Log in or Create an account to join the conversation.

Time to create page: 0.065 seconds
Powered by Kunena Forum