test - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of test.php

  1. <?php
  2. function generateOneHTMLform(){
  3.     $form = '<form>
  4.         <label>
  5.         <p>Form 1</p>
  6.         <input/>
  7.         </label>
  8.     </form>';
  9.     return $form;
  10. }
  11. function generateSecondHTMLform(){
  12.     $form = '<form>
  13.         <label>
  14.         <p>Form 2</p>
  15.         <input/>
  16.         <p>Form 2</p>
  17.         <input/>
  18.         <p>From PHP</p>
  19.         <input/>
  20.         </label>
  21.     </form>';
  22.     return $form;
  23. }?>
  24.  
  25. <body>
  26.     <style>
  27.         /*.Modal.active{*/
  28.         /*    display: block;*/
  29.         /*}*/
  30.     </style>
  31.     <section>
  32.         <p>Content</p>
  33.     </section>
  34.     <button id='first'>Button you press for form 1</button>
  35.     <section>
  36.         <p>Content2</p>
  37.     </section>
  38.     <button id='second'>Button you press for form 2</button>
  39.     
  40.     <div class="Modal" id="modal" style="position:absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 20px; background: gray; display: none;"></div>
  41.     <script>
  42.         const modalWrapper = document.querySelector('#modal');
  43.         
  44.         let firstButton = document.querySelector('#first');
  45.         let secondButton = document.querySelector('#second');
  46.         
  47.         const firstForm = `<?= generateOneHTMLform() ?>`
  48.         const secondForm = `<?= generateSecondHTMLform() ?>`
  49.         document.addEventListener('click', e => {
  50.             modalWrapper.style.display = 'none';
  51.         })
  52.         firstButton.addEventListener('click', (e) => {
  53.             e.stopPropagation();
  54.             modalWrapper.style.display = 'block';
  55.             modalWrapper.innerHTML = firstForm;
  56.         });
  57.         secondButton.addEventListener('click', (e) => {
  58.             e.stopPropagation();
  59.             modalWrapper.style.display = 'block';
  60.             modalWrapper.innerHTML = secondForm;
  61.         });
  62.     </script>
  63. </body>
File Description
  • test
  • PHP Code
  • 15 Mar-2021
  • 1.8 Kb
You can Share it: