Advertisement
Guest User

Tournaments with some Validation

a guest
Oct 9th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.26 KB | None | 0 0
  1.  
  2. <html>
  3. <body bgcolor="#000">
  4. <?php
  5.   function ExistsAndIsNotEmpty($name)
  6.   {
  7.     return (isset($_POST[$name]) && !empty($_POST[$name]));
  8.   }
  9.  
  10.   $tourneyname = (ExistsAndIsNotEmpty('tournamentname')) ? htmlentities($_POST["tournamentname"]) : '';
  11.   $start = (ExistsAndIsNotEmpty('start')) ? htmlentities($_POST["start"]) : '';
  12.   $location = (ExistsAndIsNotEmpty('location')) ? htmlentities($_POST["location"]) : '';
  13.   $prize = (ExistsAndIsNotEmpty('prize')) ? htmlentities($_POST["prize"]) : '';
  14.   $brackets = (ExistsAndIsNotEmpty('brackets')) ? htmlentities($_POST["brackets"]) : '';
  15.   $signup = (ExistsAndIsNotEmpty('signup')) ? htmlentities($_POST["signup"]) : '';
  16.   $stream = (ExistsAndIsNotEmpty('stream')) ? htmlentities($_POST["stream"]) : '';
  17.   $forum = (ExistsAndIsNotEmpty('forum')) ? htmlentities($_POST["forum"]) : '';
  18.  
  19.   if (isset($_POST['submit']))
  20.   {
  21.     if (!empty($tourneyname)
  22.       && !empty($start)
  23.       && !empty($location)
  24.       && !empty($prize)
  25.       && !empty($brackets)
  26.       && !empty($signup)
  27.       && !empty($stream)
  28.       && !empty($forum))
  29.     {
  30.       $tourneyname = htmlentities($_POST["tournamentname"]);
  31.       $start = htmlentities($_POST["start"]);
  32.       $location = htmlentities($_POST["location"]);
  33.       $prize = htmlentities($_POST["prize"]);
  34.       $brackets = htmlentities($_POST["brackets"]);
  35.       $signup = htmlentities($_POST["signup"]);
  36.       $stream = htmlentities($_POST["stream"]);
  37.       $forum = htmlentities($_POST["forum"]);
  38.  
  39.       $updatedPosts = <<< HTML
  40.         <tr>
  41.           <td>
  42.               <font color="white">$tourneyname</font>
  43.           </td>
  44.           <td>
  45.               <font color="white">$start</font>
  46.           </td>
  47.           <td>
  48.               <font color="white">$location</font>
  49.           </td>
  50.           <td>
  51.               <font color="white">$prize</font>
  52.           </td>
  53.           <td>
  54.               <font color="white"><a href="$brackets">Brackets</a></font>
  55.           </td>
  56.           <td>
  57.               <font color="white"><a href="$signup">Sign Up</a></font>
  58.           </td>
  59.           <td>
  60.               <font color="white"><a href="$stream">Stream</a></font>
  61.           </td>
  62.           <td>
  63.               <font color="white"><a href="$forum">Forum</a></font>
  64.           </td>
  65.         </tr>
  66. HTML;
  67.  
  68.       $fileHandler = fopen("posts.txt", "c");
  69.       fwrite($fileHandler, $updatedPosts);
  70.       fclose($fileHandler);
  71.     }
  72.     else
  73.     {
  74.       echo '<div class="error">';
  75.  
  76.       if (empty($tourneyname))
  77.       {
  78.         echo 'Please provide the tournament name.<br />';
  79.       }
  80.  
  81.       if (empty($start))
  82.       {
  83.         echo 'Please provide the tournament start date.<br />';
  84.       }
  85.  
  86.       if (empty($location))
  87.       {
  88.         echo 'Please provide the tournament location.<br />';
  89.       }
  90.  
  91.       if (empty($prize))
  92.       {
  93.         echo 'Please provide the prize information for the tournament.<br />';
  94.       }
  95.  
  96.       if (empty($brackets))
  97.       {
  98.         echo 'Please provide the bracket URL.<br />';
  99.       }
  100.  
  101.       if (empty($signup))
  102.       {
  103.         echo 'Please provide the sign up URL.<br />';
  104.       }
  105.  
  106.       if (empty($stream))
  107.       {
  108.         echo 'Please provide the stream URL.<br />';
  109.       }
  110.  
  111.       if (empty($forum))
  112.       {
  113.         echo 'Please provide the forum URL.<br />';
  114.       }
  115.  
  116.       echo '</div>';
  117.     }
  118.   }
  119. ?>
  120. <form id="form1" name="form1" method="post" action="">
  121.     <table>
  122.         <tr>
  123.             <td><input type="text" name="tournamentname" placeholder="Tournament Name" size="13" maxlength="20" value="<?=$tourneyname; ?>" /></td>
  124.             <td><input type="text" name="start" placeholder="01/01/0101" size="13" maxlength="10" value="<?=$start; ?>" /></td>
  125.             <td><input type="text" name="location" placeholder="SC2: Sentinel Gaming" size="13" maxlength="25" value="<?=$location; ?>" /></td>
  126.             <td><input type="text" name="prize" placeholder="$10" size="13" maxlength="10" value="<?=$prize; ?>" /></td>
  127.             <td><input type="url" name="brackets" placeholder="URL" size="10" value="<?=$brackets; ?>" /></td>
  128.             <td><input type="url" name="signup" placeholder="URL" size="10" value="<?=$signup; ?>" /></td>
  129.             <td><input type="url" name="stream" placeholder="URL" size="10" value="<?=$stream; ?>" /></td>
  130.             <td><input type="url" name="forum" placeholder="URL" size="10" value="<?=$forum; ?>" /> </td>
  131.         </tr>
  132.  
  133.         <tr>
  134.             <td colspan="8" align="right"><input type="submit" name="submit" id="submit" value="Submit Tournament" /></td>
  135.         </tr>
  136.     </table>
  137.     <table>
  138.         <tr>
  139.             <td><font color="white" size="3"><b>Tournament Name</b></font></td>
  140.             <td><font color="white" size="3"><b>Start</b></font></td>
  141.             <td><font color="white" size="3"><b>Location</b></font></td>
  142.             <td><font color="white" size="3"><b>Prize</b></font></td>
  143.             <td><font color="white" size="3"><b>Brackets</b></font></td>
  144.             <td><font color="white" size="3"><b>Signup</b></font></td>
  145.             <td><font color="white" size="3"><b>Stream</b></font></td>
  146.             <td><font color="white" size="3"><b>Forum</b></font></td>
  147.         </tr>
  148.         <?php include("posts.txt"); ?>
  149.     </table>
  150. </form>
  151. </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement