echo back array variables to html form when submitting
After alot of digging around some very informative posts and info to try
and find out how to solve this issue I thought I would ask around to see
if anyone has any pointers. I have an html form with various inputs
(checkboxes, text boxes etc...). Each input section has its own submit or
'Upload' button. On Upload a php script is called and various bits of
processing is done before data is sent over a pipe to a Python script for
further stuff. I am currently echoing back input variables to the form on
submission so that the html page does not refresh (or should I say the
inputted data is not lost to the users view) on an Upload event, however,
I now have to do the same for a bunch of checkboxes and text boxes the
values of which are stored in an array. The code I have written so far is
as follows (I am new to both php and html so please excuse the
inefficiency that I'm sure is obvious)
html/php
<margin>CH1</margin><input type="checkbox"name="ANout[]"value="AN1_OUT"
<?php if(in_array('AN1_OUT',$_POST['ANout']))echo'checked';?>>
Voltage<input type="text"size="5"name="ANout[]"
value="<?php $ANout[$i]=$_POST['ANout'];
if(!empty($ANout[$i]))echo"$ANout[$i]";?>">
<br>
The code above works fine for the checkboxes which happily remain after an
Upload button is pressed but not for the array. When the Upload event
occurs I simply get 'Array' written in the text box. I have tried existing
code I have written to echo back other text input in the form (see below)
and which works but these are for sole entries, not arrays. I have tried
various configurations of syntax but I always seem to get the same result.
Working Code:
<margin>Duty Cyle</margin><input type="text"name="PWM1DC"size="3"
value="<?php $PWM1DC = $_POST['PWM1DC'];
if(!empty($PWM1DC))echo "PWM1DC";?>">
<br>
Any clues would be appreciated.
No comments:
Post a Comment