<?php
include 'header.php'; //get the header
//functions
//Validate the title
function validatetitle(){
if(isset($_POST["submit_newnews"]) && empty($_POST["title_newnews"])) //is it empty or not
{
print ("<td>You didn't fill in a title.</td>\n");
return false;
}
else if(isset($_POST["submit_newnews"]) && (!preg_match("#^[A-Za-z0-9]+$#i", $_POST["title_newnews"])))
{
print ("<td>Title can only consist letters and numbers.</td>\n"); //have yet to add ()-_?!,.
return false;
}
else if(isset($_POST["submit_newnews"]) && !empty($_POST["title_newnews"]) && (preg_match("#^[A-Za-z0-9]+$#i", $_POST["title_newnews"])))
{
return true;
}
}
function validatecontent(){
if(isset($_POST["submit_newnews"]) && empty($_POST["content_newnews"])) //is it empty or not
{
print ("<td>You didn't fill in any news content.</td>\n");
return false;
}
else if(isset($_POST["submit_newnews"]) && (!preg_match("#^[A-Za-z0-9 .,?_!()-]+$#i", $_POST["content_newnews"])))
{
print ("<td>Content can only consist letters and numbers.</td>\n");
return false;
}
else if(isset($_POST["submit_newnews"]) && !empty($_POST["content_newnews"]) && (preg_match("#^[A-Za-z0-9]+$#i", $_POST["content_newnews"])))
{
return true;
}
}
function check(){ //check if validatetitle and validatecontent are true or not. If true you get redirected to new page
if(validatetitle() == false || validatecontent() == false){
return false;
}
if(validatetitle() == true && validatecontent() == true){
return true;
header: ('Location: upload_news.php');
}
}
?>
<div id="wrapper"> <!-- wrapper of the site needs to be closed in footer -->
<div id="wrappertop"></div>
<div id="bg"><!-- bg needs to be closed before wrapper in footer, this is for the background -->
<div id="side">
<?php include 'submenu.php'; ?>
</div>
<div id="content">
<div id="titlepage">
<h2>Upload news item</h2>
</div>
<form id="newnews" method="POST" action="<?php check() ?>" name="formnewnews"/>
<table id="formnewnews">
<tr>
<td><label>Title news article*</label></td>
<td><input type="text" name="title_newnews" id="title_newnews"/></td>
<?php validatetitle(); ?>
</tr>
<tr>
<td><label>News article**</label></td>
<td><textarea rows="6" cols="50" name="content_newnews" id="content_newnews"></textarea></td>
<?php validatecontent(); ?>
</tr>
<tr>
<td><input type="submit" name="submit_newnews" id="submit_newnews" value="upload new article"/></td>
</tr>
<tr>
<td><em style="font-size:10px;">*a-z, A-Z, 0-9 are allowed</em></td>
</tr>
<tr>
<td><em style="font-size:10px;">**a-z, A-Z, 0-9, ?!.-_() are allowed</em></td>
</tr>
</table>
</form>
</div>
<?php
include 'footer.php'; //get the footer
?>
Problemen:
- ik krijg de tekst 'You didn't fill in a title' 2 keer. 1 keer op de juiste plaats en 1 keer buiten de vlak onder het menu.
- Wanneer ik alles goed invul gaat hij naar <td>You didn't fill in a title.</td>
ps ben nieuw geen idee of ik het zo goed heb geupload ^^''
ps ik heb dislexie sorry voor eventuele spel- en grammatica fouten