rbragg Posted June 6, 2008 Share Posted June 6, 2008 Is it possible to set a form element value to an existing array? For example, I have an array called $app: <?php while (ocifetch($stmt1)) { $app = ociresult($stmt1, "FIELD"); # this is an array populated by a query results echo "<input type='checkbox' name='reminders[]' value='" . $app . "'>"; } ?> Ultimately, I would like the values in $app to be added to the reminders[] array. Is this possible or can someone divulge a way to do this? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/109039-setting-a-form-element-value-to-existing-array/ Share on other sites More sharing options...
amites Posted June 6, 2008 Share Posted June 6, 2008 something like a foreach loop foreach ($app as $row) { echo "<input type=\"checkbox\" name=\"reminders[]\" value=\"".$row['val']."\">"; } ??? Link to comment https://forums.phpfreaks.com/topic/109039-setting-a-form-element-value-to-existing-array/#findComment-559391 Share on other sites More sharing options...
rbragg Posted June 6, 2008 Author Share Posted June 6, 2008 Thanks for your reply. I don't want to echo the form element for every value in $app. I would like to set the form element = to $app. Link to comment https://forums.phpfreaks.com/topic/109039-setting-a-form-element-value-to-existing-array/#findComment-559394 Share on other sites More sharing options...
amites Posted June 6, 2008 Share Posted June 6, 2008 I'm taking a guess here that you want to set multiple values to a single radio button? easiest way would be to echo them out as a comma separated value and then explode on processing, if thats not it, then I'm not sure what your trying to do Link to comment https://forums.phpfreaks.com/topic/109039-setting-a-form-element-value-to-existing-array/#findComment-559399 Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 Best way to do this IMO is to store $app in a session to carry it to the next page... use the checkbox as a boolean <input type="checkbox" name="useApp" value="1"> Use $app? Then check for it if ( isset( $_POST['useApp'] ) ) print_r( $_SESSION['app'] ); Link to comment https://forums.phpfreaks.com/topic/109039-setting-a-form-element-value-to-existing-array/#findComment-559458 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.