Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 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.             if ($step > FINEL_STEP) {
  43.                 echo 'Благодарим за предоставленную информацию:';
  44.                 echo '<pre>';
  45.                 print_r($fields);
  46.                 echo '</pre>';
  47.                 exit;
  48.                 }
  49.  
  50.             if (empty($inputSteps[$step])) $step = 1;
  51.                 $next_step = $step+1;
  52. ?>
  53.  
  54. <!DOCTYPE html>
  55. <html>
  56. <head>
  57.     <title>Lesson 1</title>
  58. </head>
  59.     <body>
  60.         <form action="/lesson1.php" method="GET">
  61.         <?php
  62.             echo '<h2>Шаг '.$step.' из '.FINEL_STEP.'.</h2><p>';
  63.             for ($i = 1; $i < $next_step; $i++) {
  64.                 foreach ($inputSteps[$i] as $field=>$input) {  
  65.                     if ($i < $step) {
  66.                         echo sprintf($input,$fields[$field], 'hidden');
  67.                         }else{
  68.                             echo $field.': ';
  69.                             echo sprintf($input, $fields[$field], 'text');     
  70.                             }
  71.                 }
  72.             echo '</p>';
  73.             }
  74.             echo '<input type="hidden" name="step" value="'.$next_step.'" />';
  75.         ?>
  76.         <?php if ($step != FINEL_STEP): ?>
  77.             <button>Перейти к шагу <?= $next_step ?></button>
  78.         <?php else: ?>
  79.             <button>Завершить опрос!</button>
  80.         <?php endif; ?>
  81.         </form>
  82.     </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement