0

I am new to php and form development and here's what I am trying to achieve:

Firstly i have a simple form to input just two text values:

Form1
<br>
<form action="gather.php" method="post">
    Catalog:
    <input type="text" name="folderName" maxlength="50">
    <br>
    File Name:
    <input type="text" name="fileName" maxlength="50">
    <br>
    <input type="submit" name="formSubmit" value="Submit">
</form>

And now I have the second file called gather.php where i get theese two lines and use them to count files inside catalog etc.

<?php
if(isset($_POST['formSubmit'])){
    $folderName = $_POST['folderName'];
    $fileName = $_POST['fileName'];
    $numberOfImages = count(glob($folderName . "/*.jpg"));
    for($i = 1; $i <= $numberOfImages; $i++){
        echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
        echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
    }


    echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
}

?>
<br>
Final form
<br>
<form action="build.php" method="post">
<input type="submit" name="finalSubmit" value="Submit">
</form>

And this should get me to build.php file which looks more less like this:

<?php
if(isset($_POST['finalSubmit'])){
    //loop and other stuff
    $temp = $_POST['imie1'];
    echo $temp;

}
?>

So the thing is that in this final file I'd like to get all the data that was put into text fields in the gather.php file. But I get the undefined index error on build.php saying there's nothing in the $_POST['imie1']. Can you tell me why is that? Is tehre a way to get this data from second file to the third file?

Edit: thx for the answers, as I can accept only 1 and multiple are the same I choose the user with least rep just to support her :)

1
  • You need to add the form elements again to your second form, and pre-fill them with the correct values Commented Aug 6, 2012 at 12:03

3 Answers 3

2

You need to add the input inside the form tag, it won't be sent otherwise.

    <br>
    Final form
    <br>
    <form action="build.php" method="post">
    <?php
    if(isset($_POST['formSubmit'])){
        $folderName = $_POST['folderName'];
        $fileName = $_POST['fileName'];
        $numberOfImages = count(glob($folderName . "/*.jpg"));
        for($i = 1; $i <= $numberOfImages; $i++){
            echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
            echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
        }


        echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
    }

    ?>
    <input type="submit" name="finalSubmit" value="Submit">
    </form>
Sign up to request clarification or add additional context in comments.

2 Comments

they dont need that when you fill it in the browser they will be added
Right, thought it had to be filled otherwise, not by hand, ignore the value attribute part then. You're welcome.
1

Replace your gather.php with

<br>
Final form
<br>
<form action="build.php" method="post">
<?php
    if(isset($_POST['formSubmit'])){
        $folderName = $_POST['folderName'];
        $fileName = $_POST['fileName'];
        $numberOfImages = count(glob($folderName . "/*.jpg"));
        for($i = 1; $i <= $numberOfImages; $i++){
            echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n";
            echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n";
        }


        echo "\n<br>" . $folderName . "<br>" . $fileName . "\n";
    }

    ?>
<input type="submit" name="finalSubmit" value="Submit">
</form>

you was echo'ing the input boxes outside the form so now it will work

Comments

1

I think the <form> on the second form needs to come at the top of the file - it'll only submit elements inside the tag, so because you're generating your HTML and then opening the form, it's not being submitted.

<br> 
Final form 
<br> 
<form action="build.php" method="post"> 
<?php 
if(isset($_POST['formSubmit'])){ 
    $folderName = $_POST['folderName']; 
    $fileName = $_POST['fileName']; 
    $numberOfImages = count(glob($folderName . "/*.jpg")); 
    for($i = 1; $i <= $numberOfImages; $i++){ 
        echo "<br><input type=\"text\" name=\"imie" . $i . "\"><br/>\n"; 
        echo "<img src=\"" . $folderName . "/0" . $i . ".jpg\" height=\"50px\" width=\"50px\"><br><br>\n"; 
    } 


    echo "\n<br>" . $folderName . "<br>" . $fileName . "\n"; 
} 

?> 
<input type="submit" name="finalSubmit" value="Submit"> 
</form> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.