Advertisement
MizunoBrasil

Formulário de Cadastro com gerador de slug em javascript

Jan 31st, 2023 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  8.     <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
  9.     <title>Upload de imagem</title>
  10. </head>
  11. <style>
  12.     body {
  13.     font-family: 'Poppins', sans-serif;
  14.     font-size: 15px;
  15.     }
  16.     </style>
  17. <body>
  18.     <br>
  19.     <div class="container">
  20.         <h4>Cadastro</h4>
  21.         <a href="home">Início</a> | <a href="pesquisar">Pesquisar imagem</a> | <a href="https://photo16x9.com" target="_blank">https://photo16x9.com</a>
  22.         <br>
  23.  
  24. <form action="upload.php" method="post" enctype="multipart/form-data" class="slug-form container mt-5">
  25.   <div class="form-group">
  26.     <label>Nome/Título:</label>
  27.     <input type="text" name="name" id="inputText" class="form-control">
  28.   </div>
  29.   <button type="button" id="convertButton" class="btn btn-primary">Gerar Slug</button>
  30.   <br><br>
  31.   <div class="form-group">
  32.     <label>Slug Gerado:</label>
  33.     <input type="text" name="slug" id="outputText" class="form-control">
  34.   </div>
  35.   <div class="form-group">
  36.     <label>Imagem:</label>
  37.     <input type="file" name="file" class="form-control-file" accept="image/*">
  38.   </div>
  39.   <div class="form-group">
  40.     <label>Postagem:</label>
  41.     <textarea id="description" class="form-control" name="postagem" rows="15" required></textarea>
  42.   </div>
  43.   <button type="submit" class="btn btn-success">Enviar</button>
  44. </form>
  45.  
  46. <script>
  47.   const form = document.querySelector('.slug-form');
  48.   const inputText = form.querySelector('#inputText');
  49.   const outputText = form.querySelector('#outputText');
  50.   const convertButton = form.querySelector('#convertButton');
  51.  
  52.     convertButton.addEventListener('click', function() {
  53.     const inputValue = inputText.value;
  54.     const slug = inputValue.toLowerCase()
  55.       .replace(/[áàãâä]/g, 'a')
  56.       .replace(/[éèêë]/g, 'e')
  57.       .replace(/[íìîï]/g, 'i')
  58.       .replace(/[óòõôö]/g, 'o')
  59.       .replace(/[úùûü]/g, 'u')
  60.       .replace(/[ç]/g, 'c')
  61.       .replace(/[ñ]/g, 'n')
  62.       .replace(/[^a-z0-9 ]/g, '')
  63.       .replace(/\s+/g, '-')
  64.  
  65.     outputText.value = slug;
  66.   });
  67.  
  68.  
  69. </script>
  70.  
  71.     </div>
  72.    
  73.     </body>
  74.     </html>    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement