Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][PHP]Optymalizacja wyświetlania dynamicznego HTML'a
kyez
post
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 6.09.2011

Ostrzeżenie: (0%)
-----


Witajcie.

Piszę sobie taki skrypt mailingowy i zastanawiam się jak tu zopytmalizować wyświetlanie HTML'a. Chodzi o to że PHP kontroluje dane w prowadzane przez użytkownika i wyświetla odpowiedni komunikat po wysłaniu formularza. Ale wydaje mi się że rozwiązanie które zastosowałem nie jest zbyt profesjonale i optymalne.
Proszę was o podpowiedzi. (IMG:style_emoticons/default/smile.gif)
Przy okazji, jak oceniacie napisany przezemnie kod?

  1. <?php
  2. $formtresc = "
  3.  
  4. <style type='text/css'>
  5.  
  6. input{
  7. display: block;
  8. }
  9.  
  10. </style>
  11.  
  12. <div form-wrapper style='width: 400px; height: 500px; margin: 0 auto;'>
  13. <center>
  14. <form action='mail.php' method='get'>
  15. <div class='error' id='imie'></div>
  16. Your name: <input type='text' name='imie' />
  17. <div class='error' id='email'></div>
  18. Your e-mail: <input type='text' name='email' />
  19. Select subject of your message: <div class='error' id='temat'></div>
  20. <select name='subject'>
  21.  
  22. <option>Default</option>
  23. <option>Bug report</option>
  24. <option>Grats</option>
  25.  
  26.  
  27. </select></br>
  28.  
  29. Your message: <textarea name='message' cols='50' rows='10'></textarea></br></br>
  30.  
  31. <input type='submit' name='send' value='Dalej'/>
  32. </form>
  33. </center>
  34. </div>
  35. ";
  36.  
  37. $formtrescE1 = "<form action='mail.php' method='get'>
  38. <div class='error' id='imie'>Podaj imie!</div>
  39. <input type='text' name='imie' /></br>
  40. <div class='error' id='email'></div>
  41. <input type='text' name='email' />
  42. <div class='error' id='temat'></div>
  43. <select name='subject'>
  44.  
  45. <option>Default</option>
  46. <option>Bug report</option>
  47. <option>Grats</option>
  48.  
  49. </select>
  50.  
  51. <textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
  52.  
  53. <input type='submit' value='Dalej'/>
  54. </form>";
  55.  
  56. $formtrescE2 = "<form action='mail.php' method='get'>
  57. <div class='error' id='imie'></div>
  58. <input type='text' name='imie' /></br>
  59. <div class='error' id='email'>Podaj email</div>
  60. <input type='text' name='email' />
  61. <div class='error' id='temat'></div>
  62. <select name='subject'>
  63.  
  64. <option>Default</option>
  65. <option>Bug report</option>
  66. <option>Grats</option>
  67.  
  68. </select>
  69.  
  70. <textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
  71.  
  72. <input type='submit' value='Dalej'/>
  73. </form>";
  74.  
  75. $formtrescE3 = "<form action='mail.php' method='get'>
  76. <div class='error' id='imie'></div>
  77. <input type='text' name='imie' /></br>
  78. <div class='error' id='email'></div>
  79. <input type='text' name='email' />
  80. <div class='error' id='temat'>Podaj temat wiadomosci</div>
  81. <select name='subject'>
  82.  
  83. <option>Default</option>
  84. <option>Bug report</option>
  85. <option>Grats</option>
  86.  
  87.  
  88. </select>
  89.  
  90. <textarea name='message' cols='50' rows='10'>Tresc wiadomosci</textarea>
  91.  
  92. <input type='submit' value='Dalej'/>
  93. </form>";
  94.  
  95. $formtrescE4 = "<form action='mail.php' method='get'>
  96. <div class='error' id='imie'></div>
  97. <input type='text' name='imie' /></br>
  98. <div class='error' id='email'></div>
  99. <input type='text' name='email' />
  100. <div class='error' id='temat'></div>
  101. <select name='subject'>
  102.  
  103. <option>Default</option>
  104. <option>Bug report</option>
  105. <option>Grats</option>
  106.  
  107. </select>
  108. <div class='error' id='message'>Podaj tresc wiadomosci</div>
  109. <textarea name='message' cols='50' rows='10'></textarea>
  110.  
  111. <input type='submit' value='Dalej'/>
  112. </form>";
  113.  
  114.  
  115. #--------------Temporary Settings--------#
  116. # error id:
  117. # 1 - brak imienia
  118. # 2 - brak emaila
  119. # 3 - nie wybrany temat
  120. # 4 - brak tresci maila
  121.  
  122.  
  123. #$_GET['error']['id'] = '4';
  124.  
  125. #-------------End of temp. settings------#
  126.  
  127.  
  128.  
  129. #--------Configuration File Info---------#
  130. #--------------READ THIS!----------------#
  131. #
  132. # First Line: There you have an e-mail
  133. # address. Messages will be send to
  134. # that e-mail!
  135. #
  136. # Second Line: There you have color
  137. # of border of the inuts
  138. #
  139. #
  140. #
  141. #
  142. #-----End of conf. file info-------------#
  143.  
  144.  
  145.  
  146. #-------------Functions------------------#
  147. function errorExist(){
  148.  
  149. $error = isset($_GET['error']);
  150. #var_dump($a);
  151. #print_r($_GET);
  152. return $error;
  153. }
  154.  
  155. function errorIdChecker(){ # funkcja zamiast 'echo' ma zwracac id bledu dla innej funkcji
  156. if ($_GET['error']['id'] == 1) {
  157.  
  158. #echo 'brak imienia';
  159. return 1;
  160.  
  161. } elseif ($_GET['error']['id'] == 2) {
  162.  
  163. #echo "brak emaila";
  164. return 2;
  165.  
  166. } elseif ($_GET['error']['id'] == 3) {
  167.  
  168. #echo "brak tematu";
  169. return 3;
  170.  
  171. } elseif ($_GET['error']['id'] == 4) {
  172.  
  173. #echo "wpisz tresc wiadomosci";
  174. return 4;
  175.  
  176. }
  177.  
  178. } #END OF errorIdChecker function
  179.  
  180. function makePage($errorID, $trescE1, $trescE2, $trescE3, $trescE4){ // wyswietlanie odpoiedniej tresci
  181.  
  182. switch ($errorID) {
  183. case 1:
  184. echo $trescE1;
  185. break;
  186.  
  187. case 2:
  188. echo $trescE2;
  189. break;
  190.  
  191. case 3:
  192. echo $trescE3;
  193. break;
  194.  
  195. case 4:
  196. echo $trescE4;
  197. break;
  198.  
  199. default:
  200. echo "Wystapił niesnany błąd";
  201. echo "<a href='mail.php'>Go Back</a>";
  202. break;
  203.  
  204. }# Switch end
  205.  
  206. } #END OF makePage function
  207.  
  208.  
  209. function catchError(){
  210.  
  211. if (empty($_GET['imie'])){
  212. $_GET['error']['id'] = 1;
  213. return;
  214. }
  215. if (empty($_GET['email']) or !preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_GET['email'])) {
  216. $_GET['error']['id'] = 2;
  217. return;
  218. }
  219. if ($_GET['subject'] == 'Default') {
  220. $_GET['error']['id'] = 3;
  221. return;
  222. }
  223. if (empty($_GET['message'])) {
  224. $_GET['error']['id'] = 4;
  225. return;
  226. }
  227.  
  228. }
  229.  
  230. function loadConfigFile(){
  231.  
  232. $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
  233. @ $file = fopen('config.txt', 'r');
  234.  
  235. if (!$file) {
  236. echo "Blad otwarcia pliku konfiguracyjnego";
  237. } else {
  238. for ($i=0; !feof($file); $i++) {
  239.  
  240. $config[] = fgetcsv($file, 999, "]");
  241. #print_r($config);
  242. }
  243.  
  244. }
  245. return $config;
  246. }
  247.  
  248.  
  249.  
  250.  
  251. #var_dump($errorE);
  252.  
  253. if(isset($_GET['send'])){
  254. catchError();
  255. $errorE = errorExist(); //sprawdzanie czy przy ladowaniu strony jest jakis error $errorE = false/true
  256. if ($errorE == true) {
  257.  
  258. $errorId = errorIdChecker();
  259.  
  260. makePage($errorId, $formtrescE1, $formtrescE2, $formtrescE3, $formtrescE4);
  261. #print_r($a);
  262. } else{
  263. $configf = loadConfigFile();
  264. echo '<pre>';
  265. print_r($configf);
  266. echo "</pre>";
  267. $message = $_GET['message']."
  268.  
  269.  
  270.  
  271.  
  272. Author e-mail addres: ".$_GET['email'];
  273. mail($configf[0][0], $_GET['subject'], /*$_GET['message']*/$message); //not working on localhost
  274. }
  275. } else {
  276. echo $formtresc;
  277. #echo $_SERVER['DOCUMENT_ROOT'];
  278. }
  279.  
  280. // Imie
  281. // email
  282. // kategoria
  283. // tresc
  284. // dodawanie wyrazow/liczb
  285.  
  286.  
  287.  
  288. ?>
  289.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 03:40