Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. <?php
  2.  
  3. $title="";
  4. $author="";
  5. $school="";
  6. $journal="";
  7. $pubYear="";
  8. $doi="";
  9.  
  10. $error="";
  11.  
  12. function clean_text($string)
  13. {
  14. $string = trim($string);
  15. $string = stripslashes($string);
  16. $string = htmlspecialchars($string);
  17. return $string;
  18. }
  19.  
  20. if(isset($_POST["submit"]))
  21. {
  22. // Title
  23. if(empty($_POST["title"]))
  24. {
  25. $error .= '<p><label class="text-danger">Please Enter your title</label></p>';
  26. }
  27. else
  28. {
  29. $title = clean_text($_POST["title"]);
  30. if(!preg_match("/^[a-zA-Z ]*$/",$title))
  31. {
  32. $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
  33. }
  34. }
  35. // Author
  36. if(empty($_POST["author"]))
  37. {
  38. $error .= '<p><label class="text-danger">Please Enter the author.</label></p>';
  39. }
  40. else
  41. {
  42. $author = clean_text($_POST["author"]);
  43. if(!preg_match("/^[a-zA-Z ]*$/",$author))
  44. {
  45. $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
  46. }
  47. }
  48. // School
  49. if(empty($_POST["school"]))
  50. {
  51. $error .= '<p><label class="text-danger">School is required</label></p>';
  52. }
  53. else
  54. {
  55. $school = clean_text($_POST["school"]);
  56. }
  57. // pubyear
  58.  
  59. if(empty($_POST["pubYear"]))
  60. {
  61. $error .= '<p><label class="text-danger">Publication Year is required</label></p>';
  62. }
  63. else
  64. {
  65. $pubYear = clean_text($_POST["pubYear"]);
  66. if(!preg_match("/^[1-9][0-9]*$/",$pubYear));
  67. }
  68.  
  69. // Journal
  70. if(empty($_POST["author"]))
  71. {
  72. $error .= '<p><label class="text-danger">Please Enter the author.</label></p>';
  73. }
  74. else
  75. {
  76. $journal = clean_text($_POST["journal"]);
  77. if(!preg_match("/^[a-zA-Z ]*$/",$journal))
  78. {
  79. $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
  80. }
  81. }
  82. // DOI
  83.  
  84. if(empty($_POST["doi"]))
  85. {
  86. $error .= '<p><label class="text-danger">DOI is required</label></p>';
  87. }
  88. else
  89. {
  90. $doi = clean_text($_POST["doi"]);
  91. }
  92.  
  93.  
  94. if($error == '')
  95. {
  96. $openFile= fopen("publications.csv", "a");
  97.  
  98. $formData = array(
  99. 'title' => $title,
  100. 'author' => $author,
  101. 'school' => $school,
  102. 'pubYear' => $pubYear,
  103. 'journal' => $journal,
  104. 'doi' => $doi
  105. );
  106.  
  107. fputcsv($openFile, $formData);
  108. $error = '<label class="text-success">Successfully submitted publication.</label>';
  109. $title = '';
  110. $author = '';
  111. $school = '';
  112. $journal = '';
  113. $pubYear = '';
  114. $doi = '';
  115. }
  116. }
  117.  
  118. ?>
  119.  
  120. <!DOCTYPE html>
  121. <html>
  122. <head>
  123. <title>Online Publication Repository</title>
  124. <link rel="stylesheet" type="text/css" href="submit.css" />
  125.  
  126. </head>
  127. <body>
  128. <br />
  129. <div class="container">
  130. <h2 align="center">Online Publication Repository</h2>
  131. <br />
  132. <form method="post">
  133. <h3 align="center">Enter the relevant information below.</h3>
  134. <br />
  135.  
  136. <?php echo $error; ?>
  137.  
  138. <div class="form-group">
  139. <label>Enter Title</label> <br />
  140. <input type="text" name="title" placeholder="Enter Title" class="form-control" value="<?php echo $title; ?>" /> <br />
  141.  
  142. <label>Enter Author</label> <br />
  143. <input type="text" name="author" class="form-control" placeholder="Enter Author" value="<?php echo $author; ?>" /> <br />
  144.  
  145. <label>Enter School</label> <br />
  146. <select name="school" class="form-control" value="<?php echo $school; ?>" />
  147. <option>School of Chemical and Physical Sciences</option>
  148. <option>School of Computing and Maths</option>
  149. <option>School of Geography, Geology and the Environment</option>
  150. <option>School of Life Sciences</option>
  151. <option>School of Physical and Geographical Sciences</option>
  152. <option>School of Psychology</option>
  153. </select> <br />
  154.  
  155. <label>Enter Publication Year</label> <br />
  156. <input type="number" name="pubYear" class="form-control" placeholder="Enter Publication Year" value="<?php echo $pubYear; ?>" /> <br />
  157.  
  158. <label>Journal</label> <br />
  159. <input type="text" name="journal" placeholder="Enter Journal" value="<?php echo $journal; ?>" /> <br />
  160.  
  161. <label>Digital Object Identifier (DOI)</label> <br />
  162. <input type="text" name="doi" placeholder="Enter DOI" value="<?php echo $doi; ?>" /> <br />
  163.  
  164. <input type="submit" name="submit" class="btn btn-info" value="Submit" />
  165. </div>
  166. </form>
  167. </div>
  168. </body>
  169. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement