1

using PHP 5.6.27 I'm trying to generate a HTML file by combining

(1) Input from form fields

(2) HTML code (template)

Issue: The file gets created but only has the $template value but not the form field input.

Code is below. Also Live link is at http://fastlaw.in/formv2.html

Sure I'm missing something simple, but would appreciate it if anyone can help out.

formv2.html

<form action="formscriptv2.php" method="POST">

    <input id="field1" type="text"/> <br />
    <input id="field2" type="text" /> <br />

    <input type="submit" name="submit" value="Save Data">

</form>

formscriptv2.php

<?php
    $Field1 = $_POST['field1'];
    $Field2 = $_POST['field2'];

    $onepart = "
<div class='table table-left'>          
    <section>
    <h2 class='table-heading'>";

    $twopart = "</h2>           
    <table class='data'>
            <caption>
                <p>";

    $threepart = "</p>
            </caption>
    ";

$template = $onepart . $Field1 . $twopart . $Field2 . $threepart;

$ret = file_put_contents('tmp/mydata.txt', $template, FILE_APPEND | LOCK_EX);


    if($ret === false) {
        die('There was an error writing this file');
    }

    else {
        echo "$ret bytes written to file";
    }
?>
2
  • 2
    Missing name attribute in input type!! Commented Apr 18, 2017 at 13:12
  • thanks Saty, I missed this, had put in the id tag instead. Appreciate your help Commented Apr 18, 2017 at 13:36

1 Answer 1

1

PHP $_POST array are populated via the name HTML attribute:

<input id="field1" name="field1" type="text"/> <br />
<input id="field2" name="field2" type="text" /> <br />
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Matt...i put in the form code, as you did and it works now...appreciate you taking the time!

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.