Page 1 of 1

Simply Recording an Entry

Posted: Sun Aug 05, 2018 1:26 am
by SteveStifler
Hi guys and girls

How do I simply record an entry using a Dynaform I have created? Do I have to use code to tell it what to do with the fields when the submit button is pressed or can I draw a process for it? or is there a way it just knows to record an entry in PM tables? Nothing fancy, just record an entry.

Re: Simply Recording an Entry

Posted: Wed Aug 08, 2018 12:52 am
by amosbatto
If you want to write to a PM Table, you need need to use the executeQuery("INSERT ...") function in a trigger, which is executed after the Dynaform. You PM Table needs to have unique field to identify each record (which is normally called something like "ID"). If you don't want to generate the ID, then set the field to autoincrement when defining the PM Table and you won't have to include the ID field in your INSERT statement. See:
https://wiki.processmaker.com/3.0/PM_Ta ... m_Triggers

If your PM Table is named PMT_PRODUCTS has the fields ID, PRODUCT_NAME, DESCRIPTION, PRICE and AMOUNT, where ID is autoincrement, then you don't have to include ID in your INSERT statement.

Your trigger code would be:
Code: Select all
if (@@productName) {
    //use mysql_real_escape_string() to prevent SQL code injection attacks
    $name = mysql_real_escape_string(@@productName);
    $desc = mysql_real_escape_string(@@description);
    $price = @#price; //convert to float
    $amount = @%amount; //convert to integer
    //char and datetime values need to be enclosed in single quotation marks, but numbers do not:
    $sql = "INSERT INTO PMT_PRODUCTS (PRODUCT_NAME, DESCRIPTION, PRICE, AMOUNT)
        VALUES ('$name', '$desc', $price, $amount)";
    executeQuery($sql);
}
Set this trigger to execute after the Dynaform which contains fields associated with the "productName", "description", "price" and "amount" variables.

Re: Simply Recording an Entry

Posted: Tue Dec 04, 2018 11:28 pm
by amosbatto
By the way, if using PHP 7.0 or later, then use mysqli_real_escape_string() in place of mysql_real_escape_string().