Pre-populating an add form easily

Tips submitted by PHPMaker users
Post Reply
Ders
User
Posts: 1

Pre-populating an add form easily

Post by Ders »

I've always battled figuring out a tidy sustainable way to do pre-processing when doing an add form so that it is pre-filed, without hacking the generated code. The solution was easy.

The idea is scan a barcode or enter any other data, then a lot of values could be looked up from any other source, auto filling fields, making adding complex records easier.

Generate a blank page as a template (tick the box on the generate tab)
Rename this page, blankpage.php, to anything meaningful, example: add_a_scan.php
Edit this page, putting a form in it, making it post to your default add page, example itemadd.php (Be sure to enable security if required).
Test it (it will not work yet)
Now back to PHPMaker:

In my global code section I created a custom function:

function get_mypost($val) {
if ( isset($POST[$val]) && strlen(trim(@$POST[$val])) > 0 ) {
return(trim(@$_POST[$val]));
} else {
return('');
}

}

Now, in your add setup, add a default value as get_mypost("barcode")
This will automatically retrieve the value you posted from the previous page, once generated.
Likewise, based on the barcode, you can pre-fill other values into the add page. The sky's the limit.

Enjoy!


aniederer
User
Posts: 5

Post by aniederer »

There is the possibility of executing a sql inside a script js client event, when scanning the barcode of a product, a sql is executed and it brings me the last price of that product and loads it.

        //var iva = $row["idtarifas"].toNumber() * 100 / 21;

        $row["descuento"].value(descuento);

       	var elproducto = "Pollo al Horno";

        $row["producto"].value(elproducto);

        var $elprecio = ExecuteScalar("select valor from vlista_precios_activa where idproductos=39");

        $row["producto"].value($elprecio);

mgqz
User
Posts: 88

Post by mgqz »

Anieder, this you make in the add page ?

What event you use to put the code you mention? en que parte o evento pones ese javascript ?


Post Reply