Advertisement
nicolas-chuet

ajouter

Apr 21st, 2020
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. <?php
  3. include ('C:\Formation\givexpert\sitestest\modal\Domain.php');
  4. include ('C:\Formation\givexpert\sitestest\modal\Modal.php');
  5. include ('C:\Formation\givexpert\sitestest\modal\ModalManager.php');
  6.  
  7.  
  8. if (isset($_POST['title'])) {
  9.  
  10. if (!empty($_POST['title']) && !empty($_POST['text']))
  11. {
  12.  
  13. echo "le formulaire semble correct"."<br/>"." Verification de l 'url a inserer"."<br/>";
  14.  
  15. $modal = new Modal();
  16.  
  17.  
  18. foreach ($_POST['url'] as $url){
  19. if (filter_var($url, FILTER_VALIDATE_URL)) {
  20. $domain = new Domain();
  21. $domain->setUrl($url);
  22. $modal->addUrl($domain);
  23. }
  24. else {
  25. echo "non insere";
  26. echo "url :".$url." non ajouté car invalide"."</br>";
  27. }
  28. }
  29. $modal->setText($_POST['text']);
  30. $modal->setTitle($_POST['title']);
  31.  
  32. if (!empty($modal->getUrls())) {
  33.  
  34. $db = new ModalManager();
  35. $db->insertMysqli($modal);
  36. echo "Modal inseré dans la base " . "<br/>";
  37. header("Location: http://demo.local?tag=addsuccess");
  38. }else {echo "modal non ajouté suite a prob";}
  39.  
  40.  
  41. }else {
  42. die ("le formulaire est incorrect "."<br/>");
  43. }
  44. }
  45. ?>
  46. <!DOCTYPE html>
  47. <html lang="en">
  48. <head>
  49. <meta charset="UTF-8">
  50. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  51. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  52. <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
  53. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  54. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  55.  
  56. <script>
  57. $( document ).ready(function() {
  58. $( "#addUrl" ).bind( "click", function( event ) {
  59. $("#divUrl").append('<input type="text" name="url[]" /><br/>');
  60. });
  61. })
  62. </script>
  63. </head>
  64. <body>
  65. <div class="container">
  66. <form class="form-group" action="http://demo.local/ajouter.php" method="POST">
  67. TITLE MODAL: <input class="form-control" type="text" name="title" /><br/>
  68. TEXT MODAL: <textarea class="form-control" name="text" placeholder="Saisissez votre texte"></textarea>
  69. <br/>
  70. URL MODAL: <input class="form-control" type="text" name="url[]" /><br/><br/>
  71. <input class="btn btn-outline-secondary" type="button" value="Ajouter une url" id="addUrl" >
  72. <div id="divUrl"></div>
  73. <input class="btn btn-primary" type="submit" value="soumettre"><br/>
  74. </form>
  75. </div>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement