Form update and disabled fields. How can I make this work?
Posted: Wed Apr 13, 2016 7:05 am
Hi again,
so I have this form with like 50 fields to fill out. Upon submit it jumps to write_to_DB.php where i read all variables from post and write them to the database.
This part is working fine. The problem is when I want to update a form then I read from database and fill out the form from the database and disables all textfields. After each field there is a checkbox called update. When you click that checkbox it enable the line for input (or if you uncheck the field is disabled again).
This also works, but as You probably guessed by now the values in the disabled fields are not submitted to the write_to_DB.php so when i try to update it only writes the new values (from the checked (active) fields) and write over all unchecked (disabled fields) in the database with NULL.
I guess I cold do some script that enables all fields when i submit the form but I dont think its a nice solution.
I can also do a check for each variable if its set and call DB to update it but it will be an ugly code to do so for all variables...
I know there must be a way to only update the set parameters but I cannot figure out how.
Below is the code for update
Also I really want the fields to be disabled in the form.. I do not want to change to read only....(As I see ppl suggest in similar topics)
I guess I have to do some array where only the set variables go but I don't know how to do the DB update code from such an array.
Thanks
so I have this form with like 50 fields to fill out. Upon submit it jumps to write_to_DB.php where i read all variables from post and write them to the database.
This part is working fine. The problem is when I want to update a form then I read from database and fill out the form from the database and disables all textfields. After each field there is a checkbox called update. When you click that checkbox it enable the line for input (or if you uncheck the field is disabled again).
This also works, but as You probably guessed by now the values in the disabled fields are not submitted to the write_to_DB.php so when i try to update it only writes the new values (from the checked (active) fields) and write over all unchecked (disabled fields) in the database with NULL.
I guess I cold do some script that enables all fields when i submit the form but I dont think its a nice solution.
I can also do a check for each variable if its set and call DB to update it but it will be an ugly code to do so for all variables...
I know there must be a way to only update the set parameters but I cannot figure out how.
Below is the code for update
Code: Select all
if ($stmt = $mysqli->prepare("UPDATE Deviation_Report SET ArticleNumber = ?,
Wholesale = ?,
Customer = ?,
CustomerOption = ?,
CustomerFirstName = ?,
CustomerFamilyName = ?,
CustomerTelephoneNumber = ?,
CustomerEmail = ?,
ProductionDate = ?,
BestBeforeDate = ?,
BatchNumber = ?,
ProductionTime = ?,
PlantId = ?,
ClaimedAmount = ?,
ClaimedAmountUnit = ?,
SeverityGrade = ?,
DevianceDescription = ?,
SaidToCustomer = ?,
CreditOption = ?,
CreditAmount = ?,
CreditAmountUnit = ?,
UserIDWhoCredit = ?,
CreditInformation = ?,
RetrievalOption = ?,
UserIDWhoRetrieve = ?,
PickUpAdress = ?,
DeliveryAdress = ?,
PickupInformation = ?,
WarehouseCode = ?
WHERE ID = ?")) {
$stmt->bind_param('sssisssssssssisissiisisiisssss', $ArticleNumber, $Wholesale, $Customer, $CustomerData_Opt, $CustomerContactFirstName, $CustomerContactLastName, $CustomerContactTelephone, $CustomerContactEmail, $ProductionDate, $BestBeforeDate, $BatchNumber, $ProductionTime, $PlantId, $ClaimedAmount, $ClaimedAmountUnit, $SeverityGrade, $DevianceDescription, $SaidToCustomer, $Credit_Opt, $CreditAmount, $CreditAmountUnit, $WhoWillDoTheCredit, $CreditDescription, $GoodsPickup_Opt, $WhoWillDoThePickup, $PickupAdress, $GoodsDeliveryAdress, $GoodsPickupInformation, $GoodsPickupWarehouseStatus, $DevID);
$stmt->execute();
}
I guess I have to do some array where only the set variables go but I don't know how to do the DB update code from such an array.
Thanks