Hello There, Guest! Register

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Roadblock with updating database
07-29-2010, 05:19 PM, (This post was last modified: 07-29-2010, 06:04 PM by stevenm.)
#1
Roadblock with updating database
Hey guys!

I just installed THT v1.2.2 and LOVE the new features, however the included CAPTCHA didn't work for me for some reason. As a result, I began coding in functionality for THT to use reCAPTCHA instead. I've found all the TPLs and edited the PHP files, but for the life of me I can't figure out how to get THT to update the database when I click the "Edit Settings" button on the "reCAPTCHA Configuration" admin page that I created. Here's the code I currently have in recaptchasettings.tpl:

PHP Code:
<ERRORS>
<
form id="settings" name="settings" method="post" action="">
<
table width="100%" border="0" cellspacing="2" cellpadding="0">
  <
tr>
    <
td valign="top">reCAPTCHA Public Key:</td>
    <
td><input size="60" type="text" name="rc-publickey" id="rc-publickey" value="%PUBLICKEY%" /></td>
  </
tr>
  <
tr>
    <
td valign="top">reCAPTCHA Private Key:</td>
    <
td><input size="60" type="text" name="rc-privatekey" id="rc-privatekey" value="%PRIVATEKEY%" /></td>
  </
tr>
  <
tr>
    <
td colspan="2" align="center"><input type="submit" name="add" id="add" value="Edit Settings" /></td>
  </
tr>
</
table>
</
form

Very simple - it creates 2 text boxes and an "Edit Settings" button. If I manually add the public and private keys to the new rows in the database ("rc-publickey" and "rc-privatekey" in the *_config table), they will show up in the fields (with the following code added to admin/pages/settings.php):

PHP Code:
case "recaptcha":
    
$array['PUBLICKEY'] = $db->config("rc-publickey");
    
$array['PRIVATEKEY'] = $db->config("rc-privatekey");
    echo 
$style->replaceVar("tpl/recaptchasettings.tpl"$array);
    break; 

I've also added the code to the same file that will display the link to my new page.

What do I need to do to get the entered keys into the database? Help will be greatly appreciated!

P.S. I hope that all makes sense! Blush

EDIT: Another question: in orderform.tpl, how do I include PHP code, and include the $db global?
Reply
07-29-2010, 07:27 PM,
#2
RE: Roadblock with updating database
Well, you just need to edit the post function to include the lines of code that update it.

And for the orderform, you just need to perform all the code you need in the index and then use the template system to get the code on the orderform.
Jonny H - THT Main Developer & Founder


Reply
07-29-2010, 07:55 PM, (This post was last modified: 07-29-2010, 07:55 PM by Nick.)
#3
RE: Roadblock with updating database
your current ACP page already works perfectly, thanks to the fact that all submitted data on the settings page is automatically updated into the config by the following portion of admin/pages/settings.php, so nothing needs to be done there.

PHP Code:
if($_POST) {
            foreach(
$main->postvar as $key => $value) {
                if(
$value == "" && !$n) {
                    
$main->errors("Please fill in all the fields!");
                    
$n++;
                }
            }
            if(!
$n) {
                foreach(
$main->postvar as $key => $value) {
                    
$db->updateConfig($key$value);
                }
                
$main->errors("Settings Updated!");
                
$main->done();
            }
        } 

As for the orderform, do as Jonny said and put the php code in order/index.php and use the templating system ($style->replaceVar) with the %VAR% variables to get it into the order form. What you have so far looks nice, hopefully you will release this as a plugin once its done.
Nick - TheHostingTool Staff Coordinator

[Image: standard.png]

Reply
07-12-2011, 01:57 AM,
#4
RE: Roadblock with updating database
But even with such steps in place, the DBA and SQL developers encountered roadblocks when updating the databases.
Reply
07-14-2011, 08:25 PM,
#5
RE: Roadblock with updating database
(07-29-2010, 07:55 PM)Nick Wrote: your current ACP page already works perfectly, thanks to the fact that all submitted data on the settings page is automatically updated into the config by the following portion of admin/pages/settings.php, so nothing needs to be done there.

PHP Code:
if($_POST) {
            foreach(
$main->postvar as $key => $value) {
                if(
$value == "" && !$n) {
                    
$main->errors("Please fill in all the fields!");
                    
$n++;
                }
            }
            if(!
$n) {
                foreach(
$main->postvar as $key => $value) {
                    
$db->updateConfig($key$value);
                }
                
$main->errors("Settings Updated!");
                
$main->done();
            }
        } 

As for the orderform, do as Jonny said and put the php code in order/index.php and use the templating system ($style->replaceVar) with the %VAR% variables to get it into the order form. What you have so far looks nice, hopefully you will release this as a plugin once its done.

Looking back on this, my gut really hates that code's approach.
Kevin Mark - TheHostingTool Lead Developer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)