I've been two days searching how to do this. I have this form:
<form action="preview.php" method="post">
In the city of <input name="city" type="text" /> at <input name="days" type="text" /> days of <input name="month" type="text" /> gathered the following people: <input name="name1" type="text" /> and <input name="name2" type="text" /> with the objective of...
<button type="submit">Preview</button></form>
And preview.php should have this:
In the city of <?php echo $_POST['city'];?> at <?php echo $_POST['days'];?> days of <?php echo $_POST['month'];?> gathered the following people: <?php echo $_POST['name1'];?> and <?php echo $_POST['name2'];?> with the objective of...
The thing is the form is created via CMS so I have no way of knowing what the names of the inputs will be.
Is there a way to dinamically replace, for example, <input name="city" type="text" />
with <?php echo $_POST['city'];?>
?
There are some thing I have in mind but since I'm new to PHP I don't know how to implement them.
Maybe preg_replace
could do it but I don't know how to prevent the name of the input from changing.
Or maybe I could use an array, for example <input name="data[]" type="text" />
and something like:
for($i=0;"";$i++){
if( isset( $_POST["data{$i}"] )) {
$string = $form;
$patterns = '<input name="data[]" type="text" />';
$replacement = $_POST["data{$i};
preg_replace($patterns, $replacements, $string);
}
}
I'm really lost here and I'd appreciate it if someone could help me with this.
PS: I'm not a native english speaker son I'm sorry if I made some mistake.
UPDATE: The user can make different forms in the CMS that will be saved in a database. Then he can choose which one he wants to fill. Once he fills it he can preview it and save it as a pdf. The preview.php will have the same text in the form but instead of the inputs it will have the value that the user entered.