У меня относительно простая форма PHP. Когда я использую print_r($_POST);
, я ничего не получаю обратно. Как раз этот результат:
`Array
(
)
1`
Моя форма довольно проста:
<form action="" method="post" enctype="multipart/form-data" class="zip-<?php echo $atts['class']; ?>">
<div class="row ">
<div class="<?php echo $column1; ?>" <?php echo $inlineStyle ?>>
<div class="lds-facebook hide"><div></div><div></div><div></div><div></div><div></div></div>
<input type="text" name="zip" class="zip">
</div>
<div class="<?php echo $column2 ?>">
<button type="submit" class="submit" name="submit">
<?php echo $buttonValue; ?>
<i class='fa fa-caret-right' aria-hidden='true'></i>
</button>
</div>
</div>
</form>
Цель формы - просто опубликовать и затем перенаправить на страницу в зависимости от значения, полученного от ввода. Какие-нибудь мысли?
<code>public static function find_zip_widget( $atts, $content = null ) {
ini_set('display_errors', '1');
extract(shortcode_atts(array(
'class' => 'class'
), $atts));
// Set classes for rows
if($atts['class'] == 'home'){
$column1 = 'col-md-6 col-12 my-auto text-center border-underline';
$column2 = 'col-md-6 col-12';
$buttonValue = 'FIND HELP RIGHT NOW';
$inlineStyle = '';
}
if($atts['class'] == 'widget'){
$column1 = 'col-md-5 col-5 offset-2 offset-md-0 my-auto';
$column2 = 'col-md-7 col-5 my-auto';
$buttonValue = 'SUBMIT';
$inlineStyle = 'style="border-bottom: 3px solid #9EA2A4 !important;min-height: 30px;"';
}
?>
<form action="" method="post" enctype="multipart/form-data" class="zip-<?php echo $atts['class']; ?>">
<div class="row ">
<div class="<?php echo $column1; ?>" <?php echo $inlineStyle ?>>
<div class="lds-facebook hide"><div></div><div></div><div></div><div></div><div></div></div>
<input type="text" name="zip" class="zip">
</div>
<div class="<?php echo $column2 ?>">
<button type="submit" class="submit" name="submit">
<?php echo $buttonValue; ?>
<i class='fa fa-caret-right' aria-hidden='true'></i>
</button>
</div>
</div>
</form>
<?php
echo "<pre>";
echo "Before if: ";
echo print_r($_POST);
echo "
";
?>
<? PHP
$ states = get_categories (массив (
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'taxonomy' => 'endeavors_location_state'
));
if (isset ($ _ POST ['submit'])) {
$ postalZip = $ _POST ["zip"];
echo "
";
echo "After if: ";
echo print_r($_POST);
echo "
";
echo '
PostalZip:'. $ PostalZip;
/// НАПРАВЛЕНО ДЛЯ ГОРОДА, ГОСУДАРСТВА или другого /////
$ ch = curl_init ();
curl_setopt ($ ch, CURLOPT_URL, "
https://maps.googleapis.com/maps/api/geocode/json?address='.$postalZip.'&key=AIzaSyBX_0qZmGBtiHrZMcjZfv6yL7NAbLiwnjc");
// curl_setopt ($ ch, CURLOPT_URL, "
https://maps.googleapis.com/maps/api/geocode/json?address=78210&key=AIzaSyBX_0qZmGBtiHrZMcjZfv6yL7NAbLiwnjc");
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
$ output = curl_exec ($ ch);
curl_close ($ ч);
$ jsonResults = json_decode ($ output, true);
$ cityName = $ jsonResults ['results'] [0] ['address_components'] [1] ['long_name'];
$ stateName = $ jsonResults ['results'] [0] ['address_components'] [3] ['long_name'];
$ cityName = strtolower (str_replace ("", "-", $ cityName));
$ stateName = strtolower (str_replace ("", "-", $ stateName));
$ args = array (
'post_type' => 'endeavors_locations',
'post_status' => 'publish',
'число постов' => -1
);
$ cityFound = 0;
$ allCityLocations = get_posts ($ args);
foreach ($ allCityLocations как $ location) {
$ eachCity = strtolower (str_replace ("", "-", $ location-> post_name));
echo $ eachCity;
if ($ location-> post_name === $ cityName) {
$ cityFound = 1;
echo $ cityFound;
}
}
if ($ cityFound === 1) {
wp_safe_redirect ( '/ местоположения /'.$ CityName);
} еще {
foreach ($ states как $ state) {
if ($ state-> slug === $ stateName) {
$ stateFound = 1;
}
}
if ($ stateFound === 1) {
wp_safe_redirect ( '/ состояние /'.$ StateName);
} еще {
wp_safe_redirect ( '/ все-места /');
}
}
}
/// КОНЕЦ НАПРАВЛЕНИЯ ДЛЯ ГОРОДА, ГОСУДАРСТВА ИЛИ ДРУГОГО /////
} // конечная функция