Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1. <?php
  2. const FINEL_STEP = 4;
  3.         $inputSteps = [];
  4.        
  5.         $step1 = ['login' => '<input type="%2$s" name="login" value="%1$s" />',
  6.               'age' => '<input type="%2$s" name="age" value="%1$s" />',
  7.               'passwd' => '<input type="%2$s" name="passwd" value="%1$s" />'
  8.         ];
  9.    
  10.         $step2 = ['first_name' => '<input type="%2$s" name="first_name" value="%1$s" />',
  11.               'second_name' => '<input type="%2$s" name="second_name" value="%1$s" />',
  12.               'sex' => '<input type="%2$s" name="sex" value="%1$s" />'
  13.         ];
  14.    
  15.         $step3 = ['city' => '<input type="%2$s" name="city" value="%1$s" />',
  16.               'street' => '<input type="%2$s" name="street" value="%1$s" />',
  17.               'home' => '<input type="%2$s" name="home" value="%1$s" />'
  18.         ];
  19.    
  20.         $step4 = ['postcode' => '<input type="%2$s" name="postcode" value="%1$s" />',
  21.               'phone' => '<input type="%2$s" name="phone" value="%1$s" />',
  22.               'nubmerCard' => '<input type="%2$s" name="nubmerCard" value="%1$s" />'
  23.         ];
  24.  
  25.     $inputSteps = array(1 => $step1, 2 => $step2, 3 => $step3, 4 => $step4);
  26.     $step = !empty($_GET['step']) ? $_GET['step'] : 1;
  27.  
  28.         $fields = [];
  29.         $fields['login'] = !empty($_GET['login']) ? $_GET['login'] : '';
  30.         $fields['age'] = !empty($_GET['age']) ? $_GET['age'] : '';
  31.         $fields['passwd'] = !empty($_GET['passwd']) ? $_GET['passwd'] : '';
  32.         $fields['first_name'] = !empty($_GET['first_name']) ? $_GET['first_name'] : '';
  33.         $fields['second_name'] = !empty($_GET['second_name']) ? $_GET['second_name'] : '';
  34.         $fields['sex'] = !empty($_GET['sex']) ? $_GET['sex'] : '';
  35.         $fields['city'] = !empty($_GET['city']) ? $_GET['city'] : '';
  36.         $fields['street'] = !empty($_GET['street']) ? $_GET['street'] : '';
  37.         $fields['home'] = !empty($_GET['home']) ? $_GET['home'] : '';
  38.         $fields['postcode'] = !empty($_GET['postcode']) ? $_GET['postcode'] : '';
  39.         $fields['phone'] = !empty($_GET['phone']) ? $_GET['phone'] : '';
  40.         $fields['nubmerCard'] = !empty($_GET['nubmerCard']) ? $_GET['nubmerCard'] : '';
  41. ?>
  42.  
  43. <!doctype html>
  44. <html lang="en">
  45. <head>
  46.      <!-- Required meta tags -->
  47.     <meta charset="utf-8">
  48.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  49.     <!-- Bootstrap CSS -->
  50.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
  51.     <title>Lesson 1</title>
  52. </head>
  53.     <body>
  54.         <?php
  55.             if ($step > FINEL_STEP) {
  56.                 echo 'Благодарим за предоставленную информацию:';
  57.                 echo '<pre>';
  58.                 print_r($fields);
  59.                 echo '</pre>';
  60.                 exit;
  61.                 }
  62.  
  63.             if (empty($inputSteps[$step])) $step = 1;
  64.                 $next_step = $step+1;
  65.         ?>
  66.         <div class="container">
  67.             <div class="row">
  68.         <form action="/lesson1.php" method="GET">
  69.         <?php
  70.             echo '<h2>Шаг '.$step.' из '.FINEL_STEP.'.</h2><p>';
  71.             for ($i = 1; $i < $next_step; $i++) {
  72.                 foreach ($inputSteps[$i] as $field=>$input) {  
  73.                     if ($i < $step) {
  74.                         '<div class="col-md-12 col-sm-12">';
  75.                         echo sprintf($input,$fields[$field], 'hidden');
  76.                     }else{
  77.                         echo $field.': ';
  78.                         echo sprintf($input, $fields[$field], 'text');  
  79.                         '</div>';
  80.                         }
  81.                 }
  82.                 echo '</p>';
  83.             }
  84.                 echo '<input type="hidden" name="step" value="'.$next_step.'" />';
  85.         ?>
  86.         <?php if ($step != FINEL_STEP): ?>
  87.             <button>Перейти к шагу <?= $next_step ?></button>
  88.         <?php else: ?>
  89.             <button>Завершить опрос!</button>
  90.         <?php endif; ?>
  91.             </div>
  92.         </form>
  93.         </div>
  94.     <!-- Optional JavaScript -->
  95.     <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  96.     <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  97.     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
  98.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
  99.     </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement