www.webdeveloper.com
Results 1 to 4 of 4

Thread: $_SERVER['PHP_SELF'] not activating if(isset($_POST['submit']))

  1. #1
    Join Date
    May 2010
    Posts
    3

    $_SERVER['PHP_SELF'] not activating if(isset($_POST['submit']))

    Hello All, Thank in Advance!
    I am using PHP5 server side to automatically generate an HTML form from an XML file. That part works! Then, using the same script and $_SERVER['PHP_SELF'] functionality to re execute the script when it is submitted I try to write the HTML form data back to an XML file......

    I just can't seem to get the if(isset($_POST['submit'])) section of my code to execute. Any help is REALLY appreciated.



    Problem script
    ------------------------------------
    <?php
    //Do we need to present a blank form or do we need to send submitted data to a XML file?
    //If the form has already been submitted then send data to XML file
    if(isset($_POST['submit']))
    {
    //HTML form data will be saved as XML file
    //XML file will be named after HTML address field

    //Convert spaces to underscores so we have no space in our file name
    $newname = spaces2Underscore($_POST["address"]);

    //Check if there is already an existing XML file with same name
    $newxmlfile = "../properties/$newname.xml";
    if (is_file("$newxmlfile")) {
    die("Error, \"Name\" is already in use. Click your browsers \"Back\" button and try renaming.");
    }

    //Open file for writing
    $fp = fopen($newxmlfile, "w") or die("Unable to create: $newxmlfile");

    //Write data from HTML form to XML file
    foreach ($_POST as $key => $value) {
    $line ="<".$key.">".$value."</".$key.">\n";
    //echo $line;
    fputs($fp, "$line");
    }

    //Close file
    fclose($fp);
    }




    //Only execute this portion of the code if form has not been submitted
    //Use AddNewProperty.xml for template
    $template = "../properties/propertytemplate.xml" ;

    //Ensure tempalte exists
    if (!is_file("$template")) {
    die("Error, $template does not exist.");
    }

    //Open propertytemplate.xml
    $xml = simplexml_load_file("$template");

    //Use propertytemplate.xml to create HTML form
    echo "Edit the information and click \"submit\" <br /><br />";
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    <?php
    foreach($xml->children() as $child) {
    echo $child->getName() . ": " . $child . "<br />";
    echo "<input type=\"text\" size=\"60\" name=\"$child->getName()\" value=\"$child\" /><br />";
    echo "<br /><br />";
    }

    //echo "<input type=\"submit\" value=\"submit\" /><br />";
    //echo "</form>";
    ?>
    <input type="submit" value="submit" />
    </form>
    -----------------------------------------------

  2. #2
    Join Date
    May 2010
    Posts
    3

    Solved

    I had:
    <input type="submit" value="submit" />

    What I needed was:
    <input type="submit" name="submit" value="submit" />

    The if(isset($_POST['submit'])) section of my code wasn't being triggered because I had not named it i.e. name="submit"

  3. #3
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Glad you got it figured out.
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

  4. #4
    Join Date
    May 2010
    Posts
    3
    Quote Originally Posted by svidgen View Post
    Glad you got it figured out.
    Thanks, me too!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles