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
- August 3, 2015 at 10:58 pm #16410rnienaberParticipant
Hey, I’m currently trying to populate a form with information from a previously submitted form. Basically my goal is to create an ‘editable’ document.
I have 2 identical forms, Form 1 & Form 2. User fills out Form 1 (the form is submitted to a custom defined table in Settings>Database), then using a 3rd party website the User can ‘edit’ the form, this part basically consists of creating an ‘edit’ link which links to Form 2 and passes an ID via HTTP variable.
Currently I’m using these 2 guides to try and accomplish this:
Using the 2nd Tutorial, I can get the information to save in my WordPress database, but not my custom database. I followed the instructions to a T, but I can’t get the information to display when passing the generated ID.
My questions are:
– Is this the best approach, using QuForms, to create a somewhat editable form/document? (I know this creates another entry in the database but to the user it appears as though they are editing it).
– Is it possible to accomplish this using a custom table?
– Do I need to even have 2 identical forms? Or should I just populate the 1st form?Thanks again Ally – You’ve been a HUGE help and resource!
August 4, 2015 at 3:33 pm #16434AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 10, 2015 at 5:39 pm #16485rnienaberParticipantHey Ally, any update on this? Thanks
August 11, 2015 at 3:01 pm #16496AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 12, 2015 at 7:17 pm #16503rnienaberParticipantHey Ally, I followed the guide to a tee and it still isn’t populating when I pass the ‘?edit=1’ parameter.
*EDIT*
I forgot to change the SQL query to reflect my database, duh. However, the checkboxes still aren’t populating. Here are my 2 functions:
function my_save_form_data(iPhorm $form)
{
global $wpdb;
$table = ‘testdb’;// The data to save/update
$data = array(
‘Name’ => $form->getValue(‘iphorm_41_1’),
‘Email’ => $form->getValue(‘iphorm_41_2’),
‘Phone’ => $form->getValue(‘iphorm_41_3’),
‘Checkbox’ => is_array($form->getValue(‘iphorm_41_4’)) ? serialize($form->getValue(‘iphorm_41_4’)) : ”
);$rowId = absint($form->getValue(‘iphorm_41_5’));
if ($rowId > 0) {
$wpdb->update($table, $data, array(‘id’ => $rowId));
} else {
$wpdb->insert($table, $data);
}
}
add_action(‘iphorm_post_process_41’, ‘my_save_form_data’);function my_load_form_data(iPhorm $form)
{
if (!isset($_GET[‘edit’])) {
return;
}global $wpdb;
$rowId = absint($_GET[‘edit’]);$row = $wpdb->get_row($wpdb->prepare(‘SELECT * FROM testdb WHERE id = %d’, $rowId), ARRAY_A);
if (!is_array($row)) {
return;
}// The form values to set
$data = array(
‘iphorm_41_1’ => $row[‘Name’],
‘iphorm_41_2’ => $row[‘Email’],
‘iphorm_41_3’ => $row[‘Phone’],
‘iphorm_41_4’ => maybe_unserialize($row[‘Checkbox’]),
‘iphorm_41_5’ => $rowId
);$form->setValues($data);
}
add_action(‘iphorm_pre_display_41’, ‘my_load_form_data’);- This reply was modified 8 years, 8 months ago by rnienaber.
August 12, 2015 at 9:39 pm #16506rnienaberParticipantNevermind- I had it tied to the database in the Settings>Database tab!
August 13, 2015 at 5:23 pm #16516rnienaberParticipantHow could I, or is it even possible to, use this tutorial with the signature pad tutorial that you made? I’m having difficulty displaying the signature. https://support.themecatcher.net/quform-wordpress/guides/advanced/signature-field
August 15, 2015 at 2:52 pm #16523AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 19, 2015 at 10:56 pm #16546rnienaberParticipantI appreciate your help with this Ally, this functionality is very important to our form workflow.
However, this doesn’t seem to work for me (the signature will not re-display on the edited form).
Here are my 2 save/load functions:
//Database Writer
function save_form_ISP(iPhorm $form)
{
global $wpdb;
$form_db = new wpdb("root","lysorg","quformcusdb","localhost");
$table = 'tISP';
//Signature Variables
$clientSig = $form->getValue('iphorm_29_442');
$clientSig = isset($clientSig[0]['url']) ? $clientSig[0]['url'] : '';
$guardianSig = $form->getValue('iphorm_29_444');
$guardianSig = isset($guardianSig[0]['url']) ? $guardianSig[0]['url'] : '';
$staffSig = $form->getValue('iphorm_29_446');
$staffSig = isset($staffSig[0]['url']) ? $staffSig[0]['url'] : '';
$clinicianSig = $form->getValue('iphorm_29_448');
$clinicianSig = isset($clinicianSig[0]['url']) ? $clinicianSig[0]['url'] : '';
$other1Sig = $form->getValue('iphorm_29_450');
$other1Sig = isset($other1Sig[0]['url']) ? $other1Sig[0]['url'] : '';
$other2Sig = $form->getValue('iphorm_29_452');
$other2Sig = isset($other2Sig[0]['url']) ? $other2Sig[0]['url'] : '';
$approverSig = $form->getValue('iphorm_29_454');
$approverSig = isset($approverSig[0]['url']) ? $approverSig[0]['url'] : '';// The data to save/update
$data = array(
'Status' => $form->getValue('iphorm_29_439'),
'ClientSig' => $clientSig,
'GuardianSig' => $guardianSig,
'StaffSig' => $staffSig,
'ClinicianSig' => $clinicianSig,
'Other1Sig' => $other1Sig,
'Other2Sig' => $other2Sig,
'ApproverSig' => $approverSig
);$rowId = absint($form->getValue('iphorm_29_460'));
if ($rowId > 0) {
$form_db->update($table, $data, array('ID' => $rowId));
} else {
$form_db->insert($table, $data);
}
}
add_action('iphorm_post_process_29', 'save_form_ISP');
//Database Reader
function load_form_ISP(iPhorm $form)
{
if (!isset($_GET['edit'])) {
return;
}global $wpdb;
$form_db = new wpdb("root","lysorg","quformcusdb","localhost");
$rowId = absint($_GET['edit']);$row = $form_db->get_row($form_db->prepare('SELECT * FROM tISP WHERE id = %d', $rowId), ARRAY_A);
if (!is_array($row)) {
return;
}// The form values to set
$data = array(
'iphorm_29_439' => $row['Status'],
'iphorm_29_442' => $row['ClientSig'],
'iphorm_29_460' => $rowId
);$form->setValues($data);
if ($row['ClientSig'] != '') {
$content = 'data:image/png;base64,' . base64_encode(file_get_contents($row['ClientSig']));
ob_start(); ?>
<script>
jQuery(document).ready(function ($) {
var sig = '<?php echo esc_js($content); ?>';
$('.iphorm-form-29').find('input[name="signature"]').val(sig).data('SignaturePad').fromDataURL(sig);
});
</script>
<?php
$script = ob_get_clean();
$html = $form->getElement('iphorm_29_461');
if ($html instanceof iPhorm_Element_Html) {
$html->setContent($script);
}
}if ($row['GuardianSig'] != '') {
$content1 = 'data:image/png;base64,' . base64_encode(file_get_contents($row['GuardianSig']));
ob_start(); ?>
<script>
jQuery(document).ready(function ($) {
var sig1 = '<?php echo esc_js($content1); ?>';
$('.iphorm-form-29').find('input[name="signature1"]').val(sig1).data('SignaturePad1').fromDataURL(sig1);
});
</script>
<?php
$script1 = ob_get_clean();
$html1 = $form->getElement('iphorm_29_462');
if ($html1 instanceof iPhorm_Element_Html) {
$html1->setContent($script1);
}
}
}
add_action('iphorm_pre_display_29', 'load_form_ISP');
As you can see, I’ll be needing this functionality to work for forms with multiple signatures, right now I’m just trying to get it to work with two (I couldn’t get it to display with one either). When I add the line of code to my signaturePad instance:
$output.data('SignaturePad', signaturePad);
it renders the canvas’ for the other boxes unwritable.I appreciate your help in this, as this is the last piece of the puzzle for my project & QuForms has gotten me about 90% of the way so far!
Thanks,
MasonAugust 20, 2015 at 5:13 pm #16551rnienaberParticipantAlso, what is needed to redisplay the date from database? I see that you serialized the checkbox array- is something similar needed to display the date from database?
All the options on the date picker are default; except, the ‘Field order’ is set to ‘Month / Day (US)’ & the ‘Date Format’ is set to ‘2014-12-25’ or the MySQL format ‘YYYY-MM-DD’.
As always, appreciate your time and effort with this! Thanks
August 24, 2015 at 10:03 am #16587AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
September 1, 2015 at 8:04 pm #16678rnienaberParticipantThank you for your time/effort on this Ally, it is working beautifully!
Would it be difficult to update a hidden field using the edit parameter? Such as if I have Client 1 who fills out a form and submits it (with a hidden field ClientUsername & DateSubmitted that uses the WP Username/CurrentDate variable) and Client 2 goes to edit it then the hidden fields get updated with the Client 2 details?
September 1, 2015 at 8:25 pm #16683AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
September 1, 2015 at 9:13 pm #16685rnienaberParticipantThat’s what I thought & tried; however, it is not updating with the person/date (using WP Username & Current Date Stamp). The username db field is blank & the date is default 0’s.
I should note that I commented out the RowID part, so instead of saving over the current row, it creates a new autoincremented row. This is necessary for us incase of accidental deletion, form history, etc.
September 1, 2015 at 9:21 pm #16686AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.