如何在Wordpress中将变量从一个页面传递到另一个页面?
我现在正尝试在一个页面上构建表单,如果用户按下按钮[NEXT>],表单提交,
并重定向wp_redirect( $final_url ); exit;
用户到另一页继续表格。
我正在使用POST方法表单。
<form action="<?= $_SERVER['REQUEST_URI'] ?>" method="post" id="multiForm" >
<label for="client">Klients: *</label><input id="client" type="text" name="client" placeholder="Reg.nr | Pk.kods" pattern="[0-9]{10,12}" title="Jābut vismāz 10 cipariem!" required="required" maxlength="12" /></br>
<label for="selector1">Darījuma vadītājs: *</label>
<select id="selector1" name="darvad" required >
<option value="">-Dar. vadītājs-</option>
<?php
$sql = "SELECT Vards_Uzvards, Tables_ID FROM users";
$results = $wpdb->get_results($sql); // return an object, not ARRAY_N
if ($results) {
foreach ($results as $row) {
echo "<option value = '".$row->Tables_ID."'>".$row->Vards_Uzvards."</option>";
}}
echo "</select></br>";
?>
<label for="owcafind"><a href="<?php echo site_url('/sample-page/owca/'); ?>" target="_blank">Meklēt OWCA kodu:</a> *</label><input id="owcafind" type="text" name="owca" placeholder="OWCA Kods (8)" pattern="[0-9]{5,8}" title="Jābut vismāz 5 cipariem!" maxlength="8" /></br>
<label for="ldrive">Mape L diskā:</label><input id="ldrive" type="text" name="ldrive" placeholder="Mape L diskā" value="" /></br>
<label for="sanemt">Saņemšanas datums:</label><input id="sanemt" type="date" name="sanemt" placeholder="Saņemšanas datums" value="" required /></br>
</fieldset>
<label for="comment">Komentārs:</label><textarea id="comment" name="comment"></textarea></br>
<input type="submit" value="NEXT>" />
</form>
和PHP代码在同一页面中:
<!-- START PHP POST -->
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//<< Get variables from form in tsales_funnel
$darvad = esc_sql($_POST['darvad']);
$starp = esc_sql(left($_POST['owca'], 5));
$owc = esc_sql($_POST['owca']);
$ldrive = esc_sql($_POST['ldrive']);
$currentuser = wp_get_current_user()->user_login;
$sanemt = esc_sql($_POST['sanemt']);
// /Get variables >>
//<< SQL STATMENT tsales_funnel
$sql_fun = "INSERT INTO tsales_funnel (Darijuma_Vaditajs, Sanems_date, Starpnieks, OWCA, Link_L, user, adddate)
VALUES ('".$darvad."','".$sanemt."','".$starp."','".$owc."','".$ldrive."','".$currentuser."',now())
";
// SQL STATMENT tsales_funnel >>
// Insert values to tsales_funnel
$wpdb->query($sql_fun);
//------------ Add to GLOBAL variable just inserted ID--------------------
$GLOBAL['Funnelid'] = $wpdb->insert_id;
$final_url = site_url('/add-product');
wp_redirect( $final_url ); exit;
}
?>
我尝试使用$GLOBAL['Funnelid'] = $wpdb->insert_id;
,但它没有用
答案 0 :(得分:0)
您只需在url中传递此参数即可。类似的东西:
wp_redirect( $final_url . "?Funnelid=" . $wpdb->insert_id );
或者在会话中存储变量或保存在cookie中。