Populate form from custom database with HTTP GET

Home Forums Quform WordPress Populate form from custom database with HTTP GET

This topic is: resolved
Viewing 4 posts - 16 through 19 (of 19 total)
  • Author
    Posts
  • #16701
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #16705
    rnienaber
    Participant

    Awesome, this fix works pefectly!

    • This reply was modified 8 years, 7 months ago by rnienaber.
    #16938
    rnienaber
    Participant

    Ally, 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');}
    
    #17031
    rnienaber
    Participant

    Solved 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.
Viewing 4 posts - 16 through 19 (of 19 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy