Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单未第一次填充-wordpress_Php_Wordpress - Fatal编程技术网

Php 表单未第一次填充-wordpress

Php 表单未第一次填充-wordpress,php,wordpress,Php,Wordpress,我有一个表单作为自定义插件的一部分,但它在提交时不保留数据。它保存在数据库中,如果我刷新页面,它会显示信息,但我希望它第一次保持在表单中 我知道这一定是件很愚蠢的事,我只是似乎没有找到它。。。提前谢谢 代码如下: <?php global $guarantor_details; add_shortcode('guarantorForm', 'guarantor_form'); function guarantor_form() { $output = ""; global $curr

我有一个表单作为自定义插件的一部分,但它在提交时不保留数据。它保存在数据库中,如果我刷新页面,它会显示信息,但我希望它第一次保持在表单中

我知道这一定是件很愚蠢的事,我只是似乎没有找到它。。。提前谢谢

代码如下:

<?php

global $guarantor_details;

add_shortcode('guarantorForm', 'guarantor_form');

function guarantor_form()
{
$output = "";
global $current_user;
$current_user = wp_get_current_user();
$guarantor_details = getGuarantorData();


$message = (isset($_POST["guarantor_save"])) ? saveGuarantor() : false;
if ($message) $output .= '<div class="success">' . $message . '</div>';

$message = (isset($_GET["resend"]) == "true") ? generateGuarantorEmail($guarantor_details) : false;
if ($message) $output .= '<div class="success">' . $message . '</div>';

if($current_user->ID){
$output .= '
<h1>Guarantor Details</h1>
<form action="" method="POST" class="profileForm">
 <div class="formField">
        <label for="guarantor_title">Title</label>
          <select name="guarantor_title">
<option value="Mr">Mr</option>
<option value="Miss">Miss</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
</select>
    </div>
    <div class="formField">
        <label for="guarantor_name">Guarantor Full Name</label>
        <input name="guarantor_name" type="text" required
               value="' . $guarantor_details->guarantor_name . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_relationship">Relationship to student</label>
        <input name="guarantor_relationship" type="text" required
               value="' . $guarantor_details->guarantor_relationship . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_address1">Address 1</label>
        <input name="guarantor_address1" type="text" required
               value="' . $guarantor_details->guarantor_address1 . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_address2">Address 2</label>
        <input name="guarantor_address2" type="text" value="' . $guarantor_details->guarantor_address2 . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_city">City</label>
        <input name="guarantor_city" type="text" required
               value="' . $guarantor_details->guarantor_city . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_county">County</label>
        <input name="guarantor_county" type="text" required
               value="' . $guarantor_details->guarantor_county . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_postcode">Postcode</label>
        <input name="guarantor_postcode" type="text" required
               value="' . $guarantor_details->guarantor_postcode . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_country">Country</label>
<select name="guarantor_country">
        ' . countryList() . '
    </div>
    <div class="formField">
        <label for="guarantor_mobile">Mobile</label>
        <input name="guarantor_mobile" type="tel" required
               value="' . $guarantor_details->guarantor_mobile . '"/>
    </div>
         <div class="formField">
        <label for="guarantor_confirm_mobile">Confirm Mobile</label>
        <input name="guarantor_confirm_mobile" id="confirm_mobile" type="tel" required value="' . $guarantor_details->guarantor_mobile . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_telephone">Telephone</label>
        <input name="guarantor_telephone" type="tel" required
               value="' . $guarantor_details->guarantor_telephone . '"/>
    </div>
    <div class="formField">
        <label for="guarantor_email">Email</label>
        <input name="guarantor_email" type="email" required
               value="' . $guarantor_details->guarantor_email . '"/>
    </div>

    <div class="formField">
        <input name="guarantor_save" type="submit" value="Save"/>
    </div>
     <div class="formField alignRight">
    Lost the email with the link? <a href="?resend=true">Resend Email</a>
    </div>
</form>
';}
else{
    $output = 'You must <a href="'.site_url().'/login">login</a> to fill in guarantor details.';
}
return $output;

}

function getGuarantorData()
{
global $current_user;
global $wpdb;
$table = $wpdb->prefix . 'vebra_tenants';
$guarantor_details = $wpdb->get_row(
    "
SELECT *
FROM $table
WHERE tenant_user_id = $current_user->ID
"
);
return isset($guarantor_details) ? $guarantor_details : false;
return $guarantor_details;
}

//save guarantor details
function saveGuarantor()
{
global $wpdb;
global $current_user;
$guarantor_details = getGuarantorData();
$details = $_POST;
unset($details["guarantor_save"]); //no submit
unset($details["guarantor_confirm_mobile"]); //no submit

if ($guarantor_details) {
    $wpdb->update(
        $wpdb->prefix . 'vebra_tenants',
        $details,
        array('tenant_user_id' => $current_user->ID));
} else {
    $details['tenant_user_id'] = $current_user->ID;
    $wpdb->insert($wpdb->prefix . 'vebra_tenants', $details);
    $guarantor_details = getGuarantorData();
}

//let db know details updated
update_user_meta($current_user->ID, 'vebra_guarantor_details', true );

//send email if not already sent
if ($guarantor_details->guarantor_hash == "") {
    generateGuarantorEmail($guarantor_details);
    return "The guarantor details have been saved and an email has been sent to your guarantor to accept the agreement. They have seven days to respond.";
 }

//set status percentage of that property
$pcode = get_user_meta($current_user->ID, 'vebra_pcode', true);
saveStatusProgress($pcode);

return "The guarantor details have been saved";

}

function generateGuarantorEmail($guarantor_details)
{
global $current_user;
global $wpdb;

$code = md5($guarantor_details->guarantor_name);
$wpdb->update($wpdb->prefix . 'vebra_tenants',
    array('guarantor_hash' => $code,
        'guarantor_sent' => date('Y-m-d h:m:s')),
    array('tenant_user_id' => $current_user->ID,
    ));

$message = "Hello " . $guarantor_details->guarantor_name . "\n\n";
$message .= "Your name has been listed as a guarantor for a student let for " . $guarantor_details->tenant_firstname . " " . $guarantor_details->tenant_surname;
$message .= "\n\nIf you have agreed to being the guarantor, please click on the link below to go to a secure area of our website. There you will find a copy of the Assured Tenancy Agreement for the property, and the guarantor form. Please print off the guarantor form, sign and have it witnessed and then return it to us as soon as you can.";
$message .= "\n\n" . get_permalink(get_option('vebra_confirmPermalink')) . "?confirm=" . $guarantor_details->guarantor_hash;
$message .= "\n\n If you have not agreed to being a guarantor, would you please email us  to let us know.";
$message .= "\n\n Thank you for your help.\n\n \n\n";

sendEmailToPublic($guarantor_details->guarantor_email, ' ', 'Guarantor Proposal', $message);
return "An email has been sent to the guarantor with a link for them to activate and accept to be a guarantor";
}

您可能无法在
$saurer\u details
对象中获取数据库存储的值

因此,请检查您是否在
$saguarder\u details->saguarder\u name
如果没有,那么尝试解决它, 或 如果您只想显示提交的数据,那么您只需在您的案例中为
saurer\u mobile
its打印post数据即可

<input name="guarantor_mobile" type="tel" required value="'. $_POST["guarantor_mobile"].'"/>

您可能无法在
$saurer\u details
对象中获取数据库存储的值

因此,请检查您是否在
$saguarder\u details->saguarder\u name
如果没有,那么尝试解决它, 或 如果您只想显示提交的数据,那么您只需在您的案例中为
saurer\u mobile
its打印post数据即可

<input name="guarantor_mobile" type="tel" required value="'. $_POST["guarantor_mobile"].'"/>


谢谢你的回答,但我用另一种方式解决了这个问题,不得不加载
$assurant\u details=getGuarantorData()在构建表单以确保数据正确显示之前。

谢谢您的回答,但我用另一种方式解决了这个问题,必须加载
$saurant\u details=getGuarantorData()在构建表单之前,确保数据正确显示。

对不起,也许只有我一个人,但我不明白你想说什么?您想这样做吗:如果单击“保存”,数据将在不重新加载页面的情况下可见?这就是你想要的吗?嗨,Haudegen,是的,这正是我想要的:将表单保存到数据库中(正在执行),并保持数据可见(未执行)。这并不难,但使用PHP是不可能的,至少“不重新加载”功能是不可能的。当然,将数据保存到数据库是用PHP完成的。您需要使用Javascript来实现这一点。jQuery在这种情况下帮助很大。看看我之前发布的示例。使用jQuery
.append
.appendTo
。数据可以通过jQuery中的
.ajax
保存。试试这个,如果你还有问题,再问一次!也许这会有帮助:谢谢你的建议,但我认为在提交>保存>发送电子邮件(函数generateGuarantorEmail)>刷新页面上有一些东西卡住了,我就是不知道是什么。我有另一个表单工作得很好,但它没有generateGuarantorEmail函数。对不起,也许我是唯一一个,但我不明白你想说什么?您想这样做吗:如果单击“保存”,数据将在不重新加载页面的情况下可见?这就是你想要的吗?嗨,Haudegen,是的,这正是我想要的:将表单保存到数据库中(正在执行),并保持数据可见(未执行)。这并不难,但使用PHP是不可能的,至少“不重新加载”功能是不可能的。当然,将数据保存到数据库是用PHP完成的。您需要使用Javascript来实现这一点。jQuery在这种情况下帮助很大。看看我之前发布的示例。使用jQuery
.append
.appendTo
。数据可以通过jQuery中的
.ajax
保存。试试这个,如果你还有问题,再问一次!也许这会有帮助:谢谢你的建议,但我认为在提交>保存>发送电子邮件(函数generateGuarantorEmail)>刷新页面上有一些东西卡住了,我就是不知道是什么。我有另一个表单工作得很好,但它没有函数generateGuarantorEmail。谢谢各位,但它将值存储在数据库中,如果我在数据库中检查它或刷新页面,它将显示正确的数据。例如,如果我更改了名称并再次提交表单,它将显示“旧”名称,直到我刷新它。。。看起来$u details将保留浏览器上的数据,直到我刷新它为止。它快把我逼疯了!您应该在提交表单后重新加载页面,使用$page=$\u SERVER['PHP\u SELF']$第10节;标题(“刷新:$sec;url=$page”);或者只使用JavaScript的window.location.reload(),谢谢大家,但它将值存储在数据库中,如果我在数据库中检查它或刷新页面,它将显示正确的数据。例如,如果我更改了名称并再次提交表单,它将显示“旧”名称,直到我刷新它。。。看起来$u details将保留浏览器上的数据,直到我刷新它为止。它快把我逼疯了!您应该在提交表单后重新加载页面,使用$page=$\u SERVER['PHP\u SELF']$第10节;标题(“刷新:$sec;url=$page”);或者只使用JavaScript的window.location.reload()