2012-10-26 24 views
0

我走了简单的方法,并使用Web Form Builder for Mac程序为我的网站创建表单。它实际上做了一个上传到mySQL的漂亮表单的体面工作,但我真的希望它能够找到登录用户的用户ID以使用表单上传。这样我可以将提交与数据库中的Wordpress用户关联起来。获取Wordpress用户ID并使用表单提交

我的网站的用户必须登录才能访问表单,因此获取用户ID始终应该是可能的。我确实在Wordpress上找到了应该提供帮助的地方,但我不确定如何正确添加代码以及将代码添加到哪里:http://codex.wordpress.org/Function_Reference/get_userdata

我在此处附上表单的php。希望我能得到一些指导,因为这对我的网站会有很大的帮助。

理念Submission.php:

<?php 

$scriptpath = substr($_SERVER['SCRIPT_FILENAME'], 0, -4); 
$paths = explode (DIRECTORY_SEPARATOR , $scriptpath); 
$myName = end($paths); 
require $scriptpath . '/fbapp/php/config.inc.php'; 


if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { 

    $ctl = new FormController(); 
    $ctl->Dispatch(); 

} else { 

    if(! isset($_GET['action']))  $myPage->ReportStats('NotifyFormView'); 
} 

ob_start(); 

$myPage->Show(); 
ob_end_flush(); 

?> 

Form.cfg.php(我已经改变了感光材料&摆脱一些不必要的代码为这个职位):

<?php exit(0); ?> { 
"settings": 
{ 
    "data_settings" : 
    { 
     "save_database" : 
     { 
      "database" : "database", 
      "is_present" : true, 
      "password" : "password", 
      "port" : 3306, 
      "server" : "55.55.555.55", 
      "tablename" : "Submissions", 
      "username" : "username" 
     }, 
     "save_file" : 
     { 
      "filename" : "ideasubmissionform-results.csv", 
      "is_present" : true 
     }, 
     "save_sqlite" : 
     { 
      "database" : "Idea Submission.dat", 
      "is_present" : false, 
      "tablename" : "Idea Submission" 
     } 
    }, 
    "email_settings" : 
    { 
     "auto_response_message" : 
     { 
      "custom" : 
      { 
       "body" : "<!DOCTYPE html>\n<html dir=\"ltr\" lang=\"en\">\n<head>\n<title>RegisterYourApp has received your files!!</title>\n</head>\n<body>\nHello [FirstName] [LastName],\n<br>\n   We really appreciate you signing up for our services and our excited to tell you that your app idea submission for [Title] has been received! Within the next 24 hours you'll be receiving confirmation of your file(s) being stamped and your unique hash code for the submitted files.  If you've submitted multiple files they will be stamped in one zip file so will contain a single hash code and confirmation e-mail.</p>\n<br>\n<br>\n<br>\nHere's a copy of what you submitted for your records:\n<p>\n[_form_results_]\n</body>\n</html>\n", 
       "is_present" : true, 
       "subject" : "We have received your submission!!" 
      }, 
      "from" : "[email protected]", 
      "is_present" : true, 
      "to" : "[email]" 
     }, 
     "notification_message" : 
     { 
      "bcc" : "", 
      "cc" : "", 
      "custom" : 
      { 
       "body" : "<!DOCTYPE html>\n<html dir=\"ltr\" lang=\"en\">\n<head>\n<title>You got mail!</title>\n</head>\n<body>\nHey there,\n<p>\n<b>Someone filled out your form, and here's what they said:</b>\n<p>\n[_form_results_]\n</body>\n</html>\n", 
       "is_present" : false, 
       "subject" : "Idea Submission" 
      }, 
      "from" : "[email]", 
      "is_present" : true, 
      "replyto" : "[email]", 
      "to" : "[email protected]" 
     } 
    }, 
    "general_settings" : 
    { 
     "colorboxautoenabled" : false, 
     "colorboxautotime" : 3, 
     "colorboxenabled" : false, 
     "colorboxname" : "Default", 
     "formname" : "Idea Submission", 
     "is_appstore" : "0", 
     "timezone" : "America/Los_Angeles" 
    }, 
    "mailchimp" : 
    { 
     "apiKey" : "0ef1f58", 
     "lists" : 
     [ 

      { 
       "action" : 
       { 
        "subscribe" : 
        { 
         "condition" : "fields", 
         "fb_name" : "mailing_list", 
         "fb_value" : "Yes" 
        }, 
        "unsubscribe" : 
        { 
         "condition" : "never" 
        } 
       }, 
       "is_present" : true, 
       "listid" : "0bfc32032c", 
       "merge_tags" : 
       [ 

        { 
         "fb_name" : "email_mailing", 
         "field_type" : "email", 
         "isGrouping" : false, 
         "name" : "", 
         "req" : true, 
         "tag" : "EMAIL" 
        }, 

        { 
         "fb_name" : "firstname", 
         "field_type" : "text", 
         "isGrouping" : false, 
         "name" : "", 
         "req" : false, 
         "tag" : "FNAME" 
        }, 

        { 
         "fb_name" : "lastname", 
         "field_type" : "text", 
         "isGrouping" : false, 
         "name" : "", 
         "req" : false, 
         "tag" : "LNAME" 
        } 
       ], 
       "name" : "Updates & News", 
       "subscribe" : 
       { 
        "double_optin" : true, 
        "email_address_field" : "email_mailing", 
        "email_type_field" : "html", 
        "replace_interests" : true, 
        "send_welcome" : false, 
        "update_existing" : true 
       }, 
       "unsubscribe" : 
       { 
        "delete_member" : false, 
        "email_address_field" : "email_mailing", 
        "send_goodbye" : true, 
        "send_notify" : true 
       } 
      } 
     ] 
    }, 
    "payment_settings" : 
    { 
     "confirmpayment" : "", 
     "currencysymbol" : "", 
     "decimals" : 2, 
     "fixedprice" : "", 
     "invoicelabel" : "", 
     "is_present" : false, 
     "paymenttype" : "invoice", 
     "shopcurrency" : "TRY", 
     "usecustomsymbol" : false 
    }, 
    "redirect_settings" : 
    { 
     "confirmpage" : "<!DOCTYPE html>\n<html dir=\"ltr\" lang=\"en\">\n<head>\n<title>Success!</title>\n<meta charset=\"utf-8\">\n<style type=\"text/css\">\nbody {background: #f9f9f9;padding-left: 110px;padding-top: 70px; padding-right: 20px;max-width:700px;font-family: Helvetica, Arial;}\np{font-size: 16px;font-weight: bold;color: #666;}\nh1{font-size: 60px; !important;color: #ccc !important;margin:0px;}\nh2{font-size: 28px !important;color: #666 ! important;margin: 0px; border-bottom: 1px dotted #00A2FF; padding-bottom:3px;}\ntd {font-size: 12px !important; line-height: 30px; color: #666 !important; margin: 0px;border-bottom: 1px solid #e9e9e9;}\ntd:first-child {font-size: 13px !important; font-weight:bold; color: #333 !important; vertical-align:text-top; min-width:100px; padding-right:5px;}\n</style>\n</head>\n<body>\n<h1>Thanks! </h1>\n<h2>The form is on its way.</h2>\n<p>Here&rsquo;s what was sent:</p>\n<div>[_form_results_]</div>\n</body>\n</html>\n", 
     "gotopage" : "http://www.MyDomain.com/success/", 
     "inline" : "<center><h2>Thank you!</h2>\n<p>We received your form</p></center>", 
     "type" : "gotopage" 
    }, 
    "uid" : "a67968bef1ba64039314ab953a1ce923", 
    "validation_report" : "in_line" 
}, 
"rules":{"firstname":{"label":"Name","fieldtype":"text","required":true,"maxlength":"25"},"lastname":{"fieldtype":"text","required":true,"maxlength":"25"},"email":{"email":true,"label":"Email","fieldtype":"email","required":true,"equalTo":"email_verification","label_equal":"Confirm Email","maxlength":"254"},"form_of_id":{"label":"Social Security #, Driver&#39;s License, ID or Other","fieldtype":"text","required":true},"streetaddress":{"label":"Address","fieldtype":"text","required":true},"city":{"fieldtype":"text","required":true,"maxlength":"100"},"zip_code":{"fieldtype":"text","required":true,"maxlength":"25"},"state_province":{"fieldtype":"text","required":true,"maxlength":"50"},"country":{"fieldtype":"text","required":true},"phonenumber":{"phone":"phoneUS","label":"Phone Number (Optional)","fieldtype":"tel"}, 
"payment_rules":{}, 
"application_version":"Web Form Builder (OSX), build 2.1.4944" 
} 

uid.php:

<?php 

$txt = false; 

if(file_exists('form.cfg.dat')) 
    $txt = file_get_contents('form.cfg.dat'); 
else if (file_exists('form.cfg.php')) 
    $txt = file_get_contents('form.cfg.php'); 

if($txt === false) { 
    echo 'null'; 
    exit(0); 
} 

$config = json_decode(substr($txt, strpos($txt, "{")), true); 

if(isset($config['settings']) && 
    isset($config['settings']['uid'])) { 

     echo $config['settings']['uid']; 

} else { 

    echo 'null'; 
} 

?> 

Idea Submission.html(我已更改敏感内容&摆脱一些不必要的代码为这个职位):

<!DOCTYPE HTML> 
<html> 

    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <!-- Start of the headers for CoffeeCup Web Form Builder --> 
    <script type="text/javascript" src="common/js/form_init.js" data-name="" 
    id="form_init_script"> 
    </script> 
    <link rel="stylesheet" type="text/css" href="theme/blue_pad/css/default.css?version=884" 
    id="theme" /> 
    <!-- End of the headers for CoffeeCup Web Form Builder --> 
    <title> 
     Idea Submission 
    </title> 
    </head> 

    <body> 
    <!-- Start of the body content for CoffeeCup Web Form Builder --> 
    <form id="docContainer" enctype="multipart/form-data" method="POST" action="../Idea%20Submission.php" 
    novalidate="novalidate" class="fb-toplabel fb-100-item-column selected-object" 
    style="width: 650px; " data-form="manual_iframe"> 
     <div id="fb-form-header1" class="fb-form-header" style="padding-bottom: 30px; padding-top: 20px; padding-left: 35px; height: 1px; "> 
     <a id="fb-link-logo1" class="fb-link-logo" href="" target="_blank"><img alt="Alternative text" title="Alternative text" id="fb-logo1" class="fb-logo" src="common/images/image_default.png" style="display: none; "/></a> 
     </div> 
     <div id="section1" class="section"> 
     <div id="column1" class="column ui-sortable"> 
      <div style="display:none; min-height:2332px;" id="fb_confirm_inline"> 
      </div> 
      <div style="display:none;" id="fb_error_report"> 
      </div> 
      <div id="item13" class="fb-item fb-100-item-column" style="opacity: 1; "> 
      <div class="fb-header fb-item-alignment-center"> 
       <h2 style="display: inline; color: rgb(8, 2, 0); "> 
       Submit 
       </h2> 
      </div> 
      </div> 
      <div id="item14" class="fb-item fb-100-item-column" style="opacity: 1; padding-top: 0px; padding-bottom: 10px; padding-right: 0px; padding-left: 25px; "> 
      <div class="fb-static-text fb-item-alignment-center"> 
       <p style="font-style: italic; "> 
       Hello! Welcome to our submission page! 
       </p> 
      </div> 
      </div> 
      <div id="item50" class="fb-item fb-100-item-column" style="padding-bottom: 10px; padding-right: 0px; padding-left: 25px; opacity: 1; padding-top: 20px; "> 
      <div class="fb-static-text fb-item-alignment-center"> 
       <p style="font-weight: bold; "> 
       Please only upload submission per form. 
       <BR> 
       </p> 
      </div> 
      </div> 
      <div id="item51" class="fb-item fb-100-item-column" style="padding-top: 0px; padding-bottom: 10px; padding-right: 0px; padding-left: 25px; opacity: 1; "> 
      <div class="fb-static-text fb-item-alignment-center"> 
       <p> 
       You may come back as many times as you want. 
       <BR> 
       </p> 
      </div> 
      </div> 
      <div id="item1" class="fb-item fb-33-item-column" style="opacity: 1; padding-bottom: 5px; "> 
      <div class="fb-grouplabel"> 
       <label id="item1_label_0" style="display: inline; ">Name</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item1_text_1" maxlength="25" placeholder="First" 
       autocomplete="on" data-hint="" name="FirstName" required autofocus/> 
      </div> 
      </div> 
      <div id="item2" class="fb-item fb-66-item-column" style="padding-bottom: 0px; padding-top: 33px; "> 
      <div class="fb-grouplabel"> 
       <label id="item2_label_0" style="display: none; "></label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item2_text_1" maxlength="25" placeholder="Last" 
       autocomplete="on" data-hint="" name="LastName" required/> 
      </div> 
      </div> 
      <div id="item9" class="fb-item fb-100-item-column" style="padding-top: 0px; padding-bottom: 0px; opacity: 1; "> 
      <div class="fb-grouplabel"> 
       <label id="item9_label_0">Email</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="email" id="item9_email_1" maxlength="254" placeholder="[email protected]" 
       autocomplete="on" data-hint="" name="email" required/> 
       <div class="fb-hint" style="color: rgb(136, 136, 136); font-weight: normal; font-style: normal; "> 
       We will contact you by this email address. 
       </div> 
      </div> 
      <div class="fb-grouplabel"> 
       <label style="color: rgb(0, 113, 188); ">Confirm Email</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="email" id="item9_email_1_verification" maxlength="254" placeholder="" 
       autocomplete="off" data-hint="" name="email_verification" /> 
      </div> 
      </div> 
      <div id="item22" class="fb-item fb-100-item-column" style="opacity: 1; "> 
      <div class="fb-grouplabel"> 
       <label id="item22_label_0" style="display: inline; ">Social Security #, Driver&#39;s License, ID or Other</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item22_text_1" maxlength="254" placeholder="" autocomplete="off" 
       data-hint="" name="Form_Of_ID" required/> 
       <div class="fb-hint" style="color: rgb(136, 136, 136); font-weight: normal; font-style: normal; "> 
       <BR> 
       </div> 
      </div> 
      </div> 
      <div id="item3" class="fb-item fb-100-item-column" style="padding-top: 0px; padding-bottom: 0px; "> 
      <div class="fb-grouplabel"> 
       <label id="item3_label_0" style="display: inline; ">Address</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item3_text_1" maxlength="254" placeholder="Address Line 1" 
       autocomplete="on" data-hint="" name="StreetAddress" required/> 
      </div> 
      </div> 
      <div id="item5" class="fb-item fb-33-item-column" style="padding-top: 0px; padding-right: 1px; "> 
      <div class="fb-grouplabel"> 
       <label id="item5_label_0" style="display: none; "></label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item5_text_1" maxlength="100" placeholder="City" 
       autocomplete="on" data-hint="" name="City" required/> 
      </div> 
      </div> 
      <div id="item6" class="fb-item fb-33-item-column" style="opacity: 1; padding-top: 0px; padding-bottom: 0px; padding-right: 1px; padding-left: 2px; "> 
      <div class="fb-grouplabel"> 
       <label id="item6_label_0" style="display: none; "></label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item6_text_1" maxlength="25" placeholder="Postal/Zip Code" 
       autocomplete="on" data-hint="" name="Zip_Code" required/> 
      </div> 
      </div> 
      <div id="item27" class="fb-item fb-33-item-column" style="opacity: 1; padding-top: 0px; padding-right: 0px; padding-left: 2px; "> 
      <div class="fb-grouplabel"> 
       <label id="item27_label_0" style="display: none; "></label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item27_text_1" maxlength="50" placeholder="State/Province" 
       autocomplete="on" data-hint="" name="State_Province" required/> 
      </div> 
      </div> 
      <div id="item28" class="fb-item fb-50-item-column" style="opacity: 1; padding-top: 0px; padding-right: 0px; padding-left: 115px; "> 
      <div class="fb-grouplabel"> 
       <label id="item28_label_0" style="display: none; "></label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item28_text_1" maxlength="254" placeholder="Country" 
       autocomplete="on" data-hint="" name="Country" required/> 
      </div> 
      </div> 
      <div id="item19" class="fb-item fb-66-item-column" style="padding-top: 0px; opacity: 1; padding-bottom: 10px; "> 
      <div class="fb-grouplabel"> 
       <label id="item19_label_0" style="display: inline; ">Phone Number (Optional)</label> 
      </div> 
      <div class="fb-phone"> 
       <input type="tel" id="item19_tel_1" data-hint="" name="PhoneNumber" placeholder="890-123-4567" 
       /> 
      </div> 
      </div> 

      <div id="item32" class="fb-item fb-100-item-column" style="padding-top: 0px; "> 
      <div class="fb-grouplabel"> 
       <label id="item32_label_0" style="display: inline; ">Would You Like To Join Our Mailing List?</label> 
      </div> 
      <div class="fb-dropdown"> 
       <select id="item32_select_1" data-hint="" name="Mailing_List" required> 
       <option selected id="item32_0_option" value=""> 
        Choose one 
       </option> 
       <option id="item32_1_option" value="Yes"> 
        Yes 
       </option> 
       <option id="item32_2_option" value="No"> 
        No 
       </option> 
       </select> 
      </div> 
      <div class="fb-hint" style="color: rgb(136, 136, 136); font-weight: normal; font-style: normal; "> 
       Stay caught up on all the awesome things happening with the site and company. 
      </div> 
      </div> 
      <div id="item34" class="fb-item fb-100-item-column"> 
      <div class="fb-grouplabel"> 
       <label id="item34_label_0" style="display: inline; ">Email For Mailing List</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="email" id="item34_email_1" maxlength="25" placeholder="[email protected]" 
       autocomplete="on" data-hint="" name="email_mailing" required/> 
       <div class="fb-hint" style="color: rgb(136, 136, 136); font-weight: normal; font-style: normal; "> 
       The address you would like are updates sent to, if signing up for the 
       mailing list. It is a required field, but if mark &quot;no&quot; above 
       you will not be added to list. 
       </div> 
      </div> 
      </div> 
      <div id="item35" class="fb-item fb-100-item-column" style="opacity: 1; padding-bottom: 0px; "> 
      <div class="fb-grouplabel"> 
       <label id="item35_label_0" style="display: inline; ">How&#39;d You Find Out About Us? (Optional)</label> 
      </div> 
      <div class="fb-input-box"> 
       <input type="text" id="item35_text_1" maxlength="254" placeholder="ie. Friend, Google Search, Blog..." 
       autocomplete="off" data-hint="" name="HowFound" /> 
      </div> 
      </div> 
      <div id="item52" class="fb-item fb-100-item-column" style="padding-bottom: 10px; padding-right: 0px; padding-left: 25px; opacity: 1; padding-top: 20px; "> 
      <div class="fb-static-text fb-item-alignment-center"> 
       <p style="font-style: italic; "> 
       Thanks for being a member! 
       <BR> 
       <BR> 
       We guarantee to keep all your info and idea materials confidential. 
       <BR> 
       We will never look at the content of your uploaded files until you inform 
       us to do so. 
       <BR> 
       <BR> 
       </p> 
      </div> 
      </div> 
     </div> 
     </div> 
     <div id="fb-captcha_control" class="fb-captcha fb-item-alignment-center" 
     style="cursor: default; display: block; "> 
     <script type="text/javascript"> 
     var RecaptchaOptions = { theme : 'clean' }; 
     </script> 
     <script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=6Lc368kSAAAAALIQElOa6ig3G3PwwicRRKHM6gUK"> 
     </script> 
     <noscript> 
      <iframe src="https://www.google.com/recaptcha/api/noscript?k=6Lc368kSAAAAALIQElOa6ig3G3PwwicRRKHM6gUK" 
      height="300" width="500" style="border:none;"> 
      </iframe> 
      <br> 
      <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> 
      <input type="hidden" name="recaptcha_response_field" value="manual_challenge"> 
     </noscript> 
     </div> 
     <div id="fb-submit-button-div" class="fb-item-alignment-left fb-footer" 
     style="min-height: 1px; "> 
     <input type="submit" class="fb-button-special" id="fb-submit-button" data-regular="" 
     style="" value="Submit" /> 
     </div> 
     <input type="hidden" name="fb_form_custom_html" /> 
     <input type="hidden" name="fb_form_embedded" /> 
     <input type="hidden" id="fb_js_enable" name="fb_js_enable" /> 
    </form> 
    <!-- End of the body content for CoffeeCup Web Form Builder --> 
    </body> 

</html> 

THANKS SOOOOOOO多!

回答

1

Maby不是最安全的方法,但由于您的表单和wordpress是分开的,您可以在WordPress头文件的$ _SESSION中设置用户标识,并在表单页面上捕获该会话。

WordPress的是这样的:

global $current_user; 
$current_user = wp_get_current_user();  
$_SESSION['WP']['userId'] = get_userdata($current_user->ID); 

并与抓住它的窗体页上:

<input type="hidden" name="fb_form_user_id" value="<?php echo $_SESSION['WP']['userId']; ?>" /> 

希望这有助于!

+0

我只是把该输入行放在html上的隐藏字段,还是需要在其他地方?它会自动提交值与fb_form_user_id下的其余数据?我将第一个全局当前代码放在页面的标题中。谢谢! – Brad

+1

您可以将隐藏的输入字段放入您生成的HTML表单中。将它放在

标签内。您可以使用php代码来检索该值,例如$ _POST ['fb_form_user_id']; – Joey

+0

我收到的最好回应是发布<?php global $ current_user; get_currentuserinfo(); echo'用户名:'。 $ current_user-> user_login。 “\ n” 个; echo'用户名:'。 $ current_user-> ID。“\ n” 个; ?>在标题中。它在头部打印正确的用户信息(作为测试以确保获取值),但是如果我尝试在HTML表单中获取$ current_user-> ID的信息,则只能从$ current_user-> > ID不是实际的用户值。它是否必须在页面上显示为iFrame,而不是刻在wordpress主题页面中。 – Brad