Question

I'm creating a custom phpbb page. There are various text fields in the page and there is also an "add ingredient" option. If the fields are filled in with various information and then an ingredient is added, the form is submitted to add the ingredient to the session. Clearly the page refreshes at this point.

Is there a simple way to re-populate the text fields with the information they previously had via the $_POST array? I know that all the information I require is in there but with 30+ fields I was thinking that there must be a simpler/automated way of doing it, rather than adding each individual variable to the template array and then using IF statements for every field.

Thanks :)

Was it helpful?

Solution

Found the answer myself...

foreach($_POST as $id=> $row){
$id=strtoupper($id);
$template->assign_var($id, $row);
}

From there I simply used {ID_NAME} to fill in the values.

End result was

<!-- IF ID_NAME -->
<input name="id_name" type="text" id="id_name" tabindex="1" value="<!-- IF ID_NAME -->{ID_NAME}<!-- ELSE -->60<!-- ENDIF -->"/>

The lower case name of the element was then changed to upper case in order to populate it's value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top