Jump to content

Form structure


Mortier

Recommended Posts

Hello guys!!

I'm currently working out my control panel and I'm having a problem with my forms.
The news-admin section begins with an overview of all the news that has been posted and the ability to remove the selected news items, as you often see in PM boxes.

This function requires buttons to work - which means I'll need to do $_POST, because $_GET wouldn't do any good to my url which is like www.page.com?page=34&mode=5

So I use $_POST to check what the user wants to do, e.g. he wants to add news. Well then he clicks the button and the script loads the add news page (using if(isset($_POST['button'])) )

But the add news form has also got an form, which also uses $_POST.

then the script structure would look like this:
[code]
if(isset($_POST['add_news])) //the button the user clicked on in the main menu
{
     if(isset($_POST['confirm_news']) //the button the user clicked on in the add news section after typing the message
     {
      //validating and processing form

     }
     else
     {
     //load the add - news form

      }



}

[/code]

As you guys know this structure doesnt work - > after clicking the first button everything is fine, it will load the add -news form because you havent clicked the confirm news button yet, but once u finished writing the article you click the confirm news button , validating should start then,

But it does not because the first button is no longer set and you will leave both if-statements immidiatly.


For those who can understand my bad problem-explanation skills;
Any suggestions ??
Link to comment
Share on other sites

Sure

Here's the sourcecode of the add news form: ( which i include)

[code]

<?
echo '
<form enctype="multipart/form-data" method="post" action="">
<table width="302" border="0">
  <tr>
    <th width="72" scope="col"><div align="left">Onderwerp</div></th>
    <th width="220" scope="col"><div align="left">
      <input type="text" name="subject" class="form" value="' . $_POST['subject'] . '">' . $errornotify1   . '
    </div></th>
  </tr>
  <tr>
    <th scope="row" valign="top"><div align="left">Inhoud</div></th>
    <td>
      <textarea name="content" cols="40" rows="20" class="text_area">' . $_POST['content'] . '</textarea>' . $errornotify2 . '
    </td>
  </tr>
  <tr>
    <th scope="row"><div align="left">Onderdeel</div></th>
    <td><select class="select" name="section">
    <option value="wwd">World Wide Domination</option>
    <option value="gtae">Grand Theft Auto Experts</option>
    <option value="both">Beiden</option>
    </select></td>
  </tr>
  <tr>
    <th scope="row"><div align="left">Foto</div></th>
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000"  />
    <td><input type="file" name="graphic" value="' . $_POST['graphic'] . '"></td>
    
  </tr>
  <tr>
    <th scope="row"><div align="left"><input class="button2" type="submit" name="previewnews" value="Voorbeeld"></div></th>
    <td><input type="submit" class="button2" name="addnews2" value="Submit"></td>
  </tr>
</table>
</form>
' . $subjecterror . '<br>
' . $contenterror . '<br>
' . $fileerror . '
';



?>
[/code]

And the main script:

[code]
<?
function getNewsUser()
{
    $select_news = "SELECT id, author, subject, content, section, graphic, date_format(date, '%d-%m-%Y %H:%i') AS dateNL  FROM gtae_news WHERE id='" . $_GET['news'] . "'";
    $execute_news = mysql_query($select_news);
    global $fetch_news;
    $fetch_news = mysql_fetch_assoc($execute_news);
    $select_user = mysql_query('SELECT id,nickname FROM gtae_members WHERE id="' . $_SESSION['id'] . '"');
    global $fetch_user;
    $fetch_user = mysql_fetch_assoc($select_user);
    return;
}




//laatste keer bijgewerkt op 16 april 2006

setlocale(LC_TIME, 'nl_NL');
$date=date('Y-m-d H:i:s');
//nieuws met switch!
$preview_date = date('d-m-Y H:s'); //datum van post bij preview, wordt niet opgeslagen



require_once("verify.php");

if($gtae_rights == 1)
{



    switch($_GET['func'])
    {
        default:
        
        
        echo 'Here you can manage all the news that has been posted.<br>';
        $select_news =  "SELECT id, author, subject, content, section, graphic, date_format(date, '%d-%m-%Y %H:%i') AS dateNL  FROM gtae_news ORDER BY id DESC";
        $execute_news = mysql_query($select_news);
        echo '<form method="get" action=""><table>
        <tr>
         <td><strong>Subject</strong></td>
         <td><strong>Author</strong</td>
         <td><strong>Date</strong</td>
         <td><strong>Delete</strong></td>
        </tr> ';
          while($fetch_news=mysql_fetch_assoc($execute_news))
          {
            if($_GET['func'] == 'SelectAll')
            {
            $checked = 'checked';
            $select = 'DeSelect';
            $select_name = 'De-select';
            }
            else
            {
            $checked = '';
            $select = 'SelectAll';
            $select_name = 'Select all';
            }
            
            
            
            
          // gegevens verzamelen over de author omdat we ID nodig heben voor het doorsturen naar zijn profiel
          $author_id = mysql_query("SELECT id FROM gtae_members WHERE nickname='" . $fetch_news['author'] . "'");
          $fetch_author_id = mysql_fetch_assoc($author_id);
          echo '
          <tr>
          
          <td><a href="?page=19&amp;func=readnews&amp;news=' . $fetch_news['id'] . '">' . $fetch_news['subject'] . '</a></td>
          <td><a href="?page=15&amp;profile=' . $fetch_author_id['id'] . '">' . $fetch_news['author'] . '</a></td>
          <td>' . $fetch_news['dateNL'] . '</td>
          <td><input type="checkbox" name="delete" value="' . $fetch_news['id'] . '" ' . $checked . '></td>
          </tr>';
          
          
              if($_GET['func'] == DeleteMany)
            {
            $delete_query = 'DELETE FROM gtae_news WHERE id="' . $_GET['delete'] . '"';
            //$delete = mysql_query($delete_query);
            echo '' . $delete_query . '<br>';
            //echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=?page=19\">";
            }
            
            
              
          
          }
            
          echo '
          <tr>
          <td><a href="?page=19&amp;func=' . $select . '">' . $select_name . '</a></td>
          <td><a href="?page=19&amp;func=DeleteMany">Delete</a></td>
          <td><input type="submit" name="addnews" value="Add news" /></td>
          </tr>
        </table></form>';
      
      if(isset($_GET['addnews']))
      {
         if(isset($_POST['confirm_news']))
         {
        
             $goed = 1;
        
          //formulier gegevens verwerken
              $subject = $_POST['subject'];
              $content = $_POST['content'];
        
              if($content == "" OR $subject == "")
              {
              $goed = 0;
                 if($content == "")
                {
                $errornotify2 = '**';
                $contenterror = "**&amp;nbsp;&amp;nbsp;No news without content.";
                }
                if($subject == "")
                {
                $errornotify1 = '*';
                $subjecterror = "*&amp;nbsp;&amp;nbsp;A title is needed to complete your news article.";
                }
                require_once("add_news.php");
              }
        
              if($goed == 1)
              {
              $subject = strip_tags($subject);
              $subject = htmlspecialchars($subject);
              $content = strip_tags($content);
              $content = htmlspecialchars($content);
              $content = nl2br($content);
              
              require_once($_SERVER['DOCUMENT_ROOT'] . '/wwd/11/account/controlpanel/which_background.php');
              
              getNewsUser();
              
              require_once($_SERVER['DOCUMENT_ROOT'] . '/10/account/other/fetch_account.php');
              mysql_query("INSERT INTO gtae_news (author, subject, content, section, date, bg) VALUES ( '" . $fetch_user['nickname'] . "', '" . $subject . "', '" . $content . "', '" . $_POST['section'] . "', '" . $date . "', '" . $bg . "')");
               echo 'News has been added.';
              echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"1; URL=?page=19\">";
              }
           }
           else
           {
           require_once("add_news.php");
           }
        
        
          if(isset($_POST['previewnews']))
            {
        require_once("bbcode.php");
        getNewsUser();
        
        
        $content = nl2br($content);
        $content = stripslashes($content);
        echo '
        <table width="400" border="0" align="center" cellpadding="0" cellspacing="0" style="border-left: 1px solid #000000; border-right: 1px solid #000000;">
          <tr>
               <td width="250" height="25" style="padding-left: 10px;" background="img/pages/home/bg_news.jpg"><strong>Title: </strong>' . $_POST['subject'] . '</td>
               <td width="150" align="right" style="padding-right: 10px;" background="img/pages/home/bg_news.jpg"><strong>Date: </strong>' . $preview_date . '</td>
            </tr>
           <tr>
               <td colspan="2" align="justify" background="img/bg.jpg" style="padding-right: 10px; padding-left: 5px;">' . $content . '</td>
          </tr>
          <tr>
            <td height="20" colspan="2" align="right" bgcolor="#242424" style="padding-right: 10px; border-bottom: 1px solid #000000; border-top: 1px solid #000000;"><strong>Posted by: </strong>' . $fetch_user['nickname'] . '</td>
           </tr>
    
          </table>';
         $_POST['content'] = stripslashes($_POST['content']);
         $_POST['subject'] = stripslashes($_POST['subject']);
         require_once("add_news.php");
          }
      }  
        
        
        break;
        
        
        
        
        
        case "readnews":
        
        $content = $fetch_news['content'];
        require_once("bbcode.php");
        
        
        //laat het bericht zien.
    
        echo'
        <table width="400" border="0" align="center" cellpadding="0" cellspacing="0" style="border-left: 1px solid #000000; border-right: 1px solid #000000;">
          <tr>
           <td width="250" height="25" style="padding-left: 10px;" background="img/pages/home/bg_news.jpg"><strong>Title: </strong>' . $fetch_news['subject'] . '</td>
           <td width="150" align="right" style="padding-right: 10px;" background="img/pages/home/bg_news.jpg"><strong>Date:</strong> ' . $fetch_news['dateNL'] . '</td>
          </tr>
          <tr>
           <td colspan="2" align="justify" background="img/bg.jpg" style="padding-right: 10px; padding-left: 5px;">' . $content . '</td>
           </tr>
           <tr>
              <td height="20" colspan="2" align="right" bgcolor="#242424" style="padding-right: 10px; border-bottom: 1px solid #000000; border-top: 1px solid #000000;"><strong>Posted by: </strong>' . $fetch_news['author'] . '</td>
            </tr>
        </table>';
        require_once("news_include_buttons.php");
        break;
        
        
        
        
        
        
        case "delete":
        $select_news = "SELECT * FROM gtae_news WHERE id='" . $_GET['news'] . "'";
    
        $execute_news = mysql_query($select_news);
    
        $fetch_news = mysql_fetch_assoc($execute_news);
    
        echo 'Are you sure you wish to delete news item ' . $fetch_news['subject'] . '?<br>
        <table>
         <tr>
          <td><form method="post" action=?page=19&amp;news=' . $fetch_news['id'] . '&amp;func=completedelete><input class="button" type="submit" name="yes" value="Yes"></form></td>
          <td><form method="post" action=?page=19><input class="button"  type="submit" name="no" value="No"></form></td>
         </tr>
        </table>
        ';
        break;
        
        
        
        case "completedelete":
        $select_news = "SELECT * FROM gtae_news WHERE id='" . $_GET['news'] . "'";
    
        $execute_news = mysql_query($select_news);
    
        $fetch_news = mysql_fetch_assoc($execute_news);
    
        mysql_query("DELETE FROM gtae_news WHERE id='" . $_GET['news'] . "'");
        echo 'The message has been deleted.';
        echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"1; URL=?page=19\">";
        break;
        
        case "massivedelete":
        
        
        
        
        case "edit":
        $select_news = "SELECT * FROM gtae_news WHERE id='" . $_GET['news'] . "'";
        
        $execute_news = mysql_query($select_news);
    
        $fetch_news = mysql_fetch_assoc($execute_news);
    
        //een formuliertje waarin alle gegevens van het nieuws bericht staan
        
    
        if(isset($_POST['editnews']))
        {
        $goed = 1;
            if($_POST['subject'] == "" OR $_POST['content'] == "" OR $_POST['subject'] == "You must enter a title." OR $_POST['content'] == "You must enter some content.")
             {
                $goed = 0;
                 if($_POST['subject'] == "" OR $_POST['subject'] == "You must enter a title." )
                {
                $subject = "You must enter a title.";
                }
                if($_POST['content'] == "" OR $_POST['content'] == "You must enter some content.")
                {
                $content = "You must enter some content.";
                }
                require_once("edit_news.php");
            }
        
        
            if($goed == 1)
            {
            //nieuws bijwerken
            $subject = strip_tags($_POST['subject']);
            $subject = htmlspecialchars($subject);
            $content = strip_tags($_POST['content']);
            $content = htmlspecialchars($content);
            $content = nl2br($content);
            //$content = stripslashes($content);
            $updatenews = "UPDATE gtae_news SET subject='" . $subject . "', content='" . $content . "', section='" . $_POST['section'] . "' WHERE id='" . $_GET['news'] . "'";
            echo 'News has been edited.';
            echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"1; URL=?page=19\">";
            mysql_query($updatenews) or die(mysql_error());
            }
        }
        elseif((!isset($_POST['previewedit']))) //er mag ook niet op preview geklikt zijn, daar krijgen we alleen maar rommel van!
        {
        require_once("edit_news.php");
        }
        
        if(isset($_POST['previewedit']))
        {
        
        getNewsUser();
        
        require_once("bbcode.php");
        $content = nl2br($content);
        $content = stripslashes($content);
        echo '<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" style="border-left: 1px solid #000000; border-right: 1px solid #000000;">
        <tr>
        <td width="250" height="25" style="padding-left: 10px;" background="img/pages/home/bg_news.jpg"><strong>Title: </strong>' . $_POST['subject'] . '</td>
        <td width="150" align="right" style="padding-right: 10px;" background="img/pages/home/bg_news.jpg"><strong>Date: </strong>' . $date . '</td>
      </tr>
      <tr>
        <td colspan="2" align="justify" background="img/bg.jpg" style="padding-right: 10px; padding-left: 5px;">' . $content . '</td>
      </tr>
      <tr>
        <td height="20" colspan="2" align="right" bgcolor="#242424" style="padding-right: 10px; border-bottom: 1px solid #000000; border-top: 1px solid #000000;"><strong>Posted by: </strong>' . $fetch_user['nickname'] . '</td>
      </tr>
    
      </table>';
         //we selecteren opniew de gegevens omdat we anders problemen krijgen met een oud add news formuliertje waarvan de gegevens na preview niet bijgewerkt worden
        $select_news = "SELECT * FROM gtae_news WHERE id='" . $_GET['news'] . "'";
        
        $execute_news = mysql_query($select_news);
    
        $fetch_news = mysql_fetch_assoc($execute_news);
        
        $fetch_news['content'] = stripslashes($fetch_news['content']);
        require_once("edit_news.php");
          }
        
        break;
        
    }

}
else
{
require_once($_SERVER['DOCUMENT_ROOT'] . '/10/no_acces.php');
}
[/code]

Well you probably find this quite a mess and im busy optimalizing it too but I will need the best structure first.

As you see I use switch, A GET switch because else you would get weird buttons (becuase it checks the button value and u usually make buttons called like Submit and you need them al to be unique using POST switch).

It quite works this way, the current code is experimental and that with the double isset POSt doesnt work ofcourse, I used to do that as a different case but then I cant use buttons anymore in the form??
AAH very confusing that's why I want to alter my structure :)


EDIT: I will post a structure of my current script in a few min because this isnt really getting better, too many irrelevent coding :)
Link to comment
Share on other sites

ok here's an overview. The main form which is the default-case is the actual problem because it's so messy and unlogical.

[code]
<?
//structure of news.php

switch($_GET['func'])
{
    default:
    //form with all news + buttons
    
    //delete function with checkboxes, must be in this case because it has to be in the while-loop
    
    //add news at current working state also in the default mode, this works but its very messy. (many if-messing as you see above)
    break;
    
    case 'readnews';
    //works all fine
    break;
    
    case 'etc..etc..';
    
        
}
?>
[/code]
Link to comment
Share on other sites

Not read your post fully - it's too big for me!!!

A suggestion.....

Why not have a checkbox beside each item in yur form instaed of a submit button. Then at the bottom o fthe form a method of selecting an action (edit, delete etc.) like set of radio buttons or a select box.

That way you can use just one submit button and do alot more like deleting multiple items....
Link to comment
Share on other sites

[!--quoteo(post=368919:date=Apr 26 2006, 07:47 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 26 2006, 07:47 PM) [snapback]368919[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Not read your post fully - it's too big for me!!!

A suggestion.....

Why not have a checkbox beside each item in yur form instaed of a submit button. Then at the bottom o fthe form a method of selecting an action (edit, delete etc.) like set of radio buttons or a select box.

That way you can use just one submit button and do alot more like deleting multiple items....
[/quote]

Ok so with POST or GET, it has to be GET because how will I else keep the information set?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.