Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $title="";
- $author="";
- $school="";
- $journal="";
- $pubYear="";
- $doi="";
- $error="";
- function clean_text($string)
- {
- $string = trim($string);
- $string = stripslashes($string);
- $string = htmlspecialchars($string);
- return $string;
- }
- if(isset($_POST["submit"]))
- {
- // Title
- if(empty($_POST["title"]))
- {
- $error .= '<p><label class="text-danger">Please Enter your title</label></p>';
- }
- else
- {
- $title = clean_text($_POST["title"]);
- if(!preg_match("/^[a-zA-Z ]*$/",$title))
- {
- $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
- }
- }
- // Author
- if(empty($_POST["author"]))
- {
- $error .= '<p><label class="text-danger">Please Enter the author.</label></p>';
- }
- else
- {
- $author = clean_text($_POST["author"]);
- if(!preg_match("/^[a-zA-Z ]*$/",$author))
- {
- $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
- }
- }
- // School
- if(empty($_POST["school"]))
- {
- $error .= '<p><label class="text-danger">School is required</label></p>';
- }
- else
- {
- $school = clean_text($_POST["school"]);
- }
- // pubyear
- if(empty($_POST["pubYear"]))
- {
- $error .= '<p><label class="text-danger">Publication Year is required</label></p>';
- }
- else
- {
- $pubYear = clean_text($_POST["pubYear"]);
- if(!preg_match("/^[1-9][0-9]*$/",$pubYear));
- }
- // Journal
- if(empty($_POST["author"]))
- {
- $error .= '<p><label class="text-danger">Please Enter the author.</label></p>';
- }
- else
- {
- $journal = clean_text($_POST["journal"]);
- if(!preg_match("/^[a-zA-Z ]*$/",$journal))
- {
- $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
- }
- }
- // DOI
- if(empty($_POST["doi"]))
- {
- $error .= '<p><label class="text-danger">DOI is required</label></p>';
- }
- else
- {
- $doi = clean_text($_POST["doi"]);
- }
- if($error == '')
- {
- $openFile= fopen("publications.csv", "a");
- $formData = array(
- 'title' => $title,
- 'author' => $author,
- 'school' => $school,
- 'pubYear' => $pubYear,
- 'journal' => $journal,
- 'doi' => $doi
- );
- fputcsv($openFile, $formData);
- $error = '<label class="text-success">Successfully submitted publication.</label>';
- $title = '';
- $author = '';
- $school = '';
- $journal = '';
- $pubYear = '';
- $doi = '';
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Online Publication Repository</title>
- <link rel="stylesheet" type="text/css" href="submit.css" />
- </head>
- <body>
- <br />
- <div class="container">
- <h2 align="center">Online Publication Repository</h2>
- <br />
- <form method="post">
- <h3 align="center">Enter the relevant information below.</h3>
- <br />
- <?php echo $error; ?>
- <div class="form-group">
- <label>Enter Title</label> <br />
- <input type="text" name="title" placeholder="Enter Title" class="form-control" value="<?php echo $title; ?>" /> <br />
- <label>Enter Author</label> <br />
- <input type="text" name="author" class="form-control" placeholder="Enter Author" value="<?php echo $author; ?>" /> <br />
- <label>Enter School</label> <br />
- <select name="school" class="form-control" value="<?php echo $school; ?>" />
- <option>School of Chemical and Physical Sciences</option>
- <option>School of Computing and Maths</option>
- <option>School of Geography, Geology and the Environment</option>
- <option>School of Life Sciences</option>
- <option>School of Physical and Geographical Sciences</option>
- <option>School of Psychology</option>
- </select> <br />
- <label>Enter Publication Year</label> <br />
- <input type="number" name="pubYear" class="form-control" placeholder="Enter Publication Year" value="<?php echo $pubYear; ?>" /> <br />
- <label>Journal</label> <br />
- <input type="text" name="journal" placeholder="Enter Journal" value="<?php echo $journal; ?>" /> <br />
- <label>Digital Object Identifier (DOI)</label> <br />
- <input type="text" name="doi" placeholder="Enter DOI" value="<?php echo $doi; ?>" /> <br />
- <input type="submit" name="submit" class="btn btn-info" value="Submit" />
- </div>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement