Home › Forums › Quform WordPress › Populate form from custom database with HTTP GET
- This topic has 18 replies, 2 voices, and was last updated 8 years, 7 months ago by rnienaber.
- AuthorPosts
- September 2, 2015 at 12:09 pm #16701AllySupport Staff
You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
September 2, 2015 at 9:15 pm #16705rnienaberParticipantAwesome, this fix works pefectly!
- This reply was modified 8 years, 7 months ago by rnienaber.
September 29, 2015 at 5:12 pm #16938rnienaberParticipantAlly, I’m trying to brainstorm of a way to prevent users from changing a field on edit. Example:
If I have a simple client form: Client Name (dropdown populated via database query), & Favorite Color.
I want the user to be able to select a client name from the dropdown & select a favorite color, this creates row #1 in the database. Using the ‘edit’ functions you’ve outlined here, I would call form?edit=1 to retrieve this record and populate for editing; however, I don’t want the user to be able to change the user’s name from the dropdown on edit.
My solution is to create a ‘hidden’ field so when the first form is submitted the username is stored in 2 places in the database (ClientName, ClientNameHidden, FavColor), and when it is edited the hidden field is populated with the contents from the database field. My problem is that I am unable to keep the contents of the ‘hidden’ field static because it is using the same save function so it is submitted based off the value of the dropdown selected, where i’d like it to save based on the value of the database.
Do you have any ideas to get around this? I’m thinking maybe an IF statement in the 1st save function so if a ‘EDIT’ GET parameter is passed then it will store the contents of the clientid from the database in a variable using the rowID passed, instead of retrieving that value from the form.
IF ($_GET['edit'] ! == NULL){ $rowId = absint($_GET['edit']); $row = $form_db->get_row($form_db->prepare('SELECT * FROM TABLE WHERE RowID = %d', $rowId), ARRAY_A); $ClientID_Hidden = $row['ClientID_Hidden'];} else{$ClientID_Hidden = $form->getValue('iphorm_13_100');}
September 29, 2015 at 9:23 pm #17031rnienaberParticipantSolved the issue with a little re-arranging of my code in the save function:
`$ID = $_GET[“edit”];
IF ($ID == NULL){
$ClientID_Hidden = $form->getValue(‘iphorm_13_100’);
}
ELSE{
$row = $form_db->get_row($form_db->prepare(‘SELECT * FROM tClientDemo WHERE RowID = %d’, $ID), ARRAY_A);
$ClientID_Hidden = $row[‘ClientID_Hidden’];
}`- This reply was modified 8 years, 7 months ago by rnienaber.
- AuthorPosts
- You must be logged in to reply to this topic.