SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Embedded form not being processed

    I am attempting to preview some content I intend to add to the database once I have ok'd it. I have done this before, but never when the whole page is written in PHP, i.e. the form tag is used through an echo line as you can see below.

    PHP Code:
    if ($submit == "preview") {
                         echo "<p><b>Your content will appear as:</b></p>\n";
                         echo "<div id='preview'>\n";
                         echo "<p>$_POST[issue]</p>\n";
                         echo "<h2>$_POST[title]</h2>\n";
                         echo "<p><i>$_POST[abstract]</i></p>\n";
                         echo $_POST[copy];
                         echo "</div>\n";
                         echo "<br clear='all' />";
                     }
             
                     echo "<form action='<?=$PHP_SELF?>' method='post' class='formEdit'>\n";
    The reason why the form tage is in the PHP is because the page is used to add more than one type of content, therefore all the content is in one big if statement.

    Can anybody tell me why this isn't working?
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding a single quote around your variables like...
    PHP Code:
    echo "<h2>$_POST['title']</h2>\n"
    Lats...

  3. #3
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done, but that hasn't helped. It appears the form is not being processed at all. Is there a way to see if it is?
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    Quote Originally Posted by Alexandra
    Is there a way to see if it is?
    Put this at the top of your page. It will print out everything that is in the $_POST array:
    PHP Code:
    echo '<pre>';
    print_r($_POST);
    echo 
    '</pre>'
    Also see: Tip: print_r() and var_dump().

    -Helge

  5. #5
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that has helped somewhat. I now know the data is being sent through the form, it just isn't previewing....why could that be?

    This is the result of the test:

    PHP Code:
    Array
      (
          [
    section] => column
          
    [issue] => Feb 04
          
    [title] => Web Page Potpourri
          
    [abstract] => 
          [
    copy] => 
          [
    preview] => Preview column
      

    And, again, this is the code to display the preview...is there something wrong with it?

    PHP Code:
    else if ($submit == "Preview") {
                         echo 
    "<p><b>Your content will appear as:</b></p>\n";
                         echo 
    "<div id='preview'>\n";
                         echo 
    "<p>$_POST['issue']</p>\n";
                         echo 
    "<h2>$_POST['title']</h2>\n";
                         echo 
    "<p><i>$_POST['abstract']</i></p>\n";
                         echo 
    $_POST['copy'];
                         echo 
    "</div>\n";
                         echo 
    "<br clear='all' />";
                      } 
    And the button that calls the form:

    PHP Code:
    <input type='submit' name='preview' id='preview' value='Preview' /> 
    This has really got me stumped...
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of if($submit == "Preview") try
    if(!empty($_POST['preview']))

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking at this line
    PHP Code:
    else if ($submit == "Preview") { 
    it appears you're looking for a button named submit, but further down you have named it 'preview'.

    Try:
    PHP Code:
    elseif (!empty($_POST['preview'])) { 
    -Helge
    Edit:

    Too late...

  8. #8
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Mark and Helge, you are both right. I've changed that line and it is now working.
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •