fmpros Posted August 13, 2009 Share Posted August 13, 2009 Hello, I've got a dynamic value list using php and FileMaker Pro. I'm trying to include the $POST value so that the user doesn't have to re-enter their info if the form returns an error. Here is the code: $records1 = $result1->getRecords(); $session1_popup = '<select name="session1" id="session1"><option value="" label=""</option>'; foreach($records1 as $record1) { $value1 = $record1->getField('field_a'); $label1 = $record1->getField('field_b'); $session1_popup.= '<option value="' . $value1 . '">' . $label1 . '</option>'; } $session1_popup.= '</select>'; The above code works as expected. What I'd like to do now is add a $POST value to line #2. I'm not quite sure what syntax to use. Something like this? $session1_popup = '<select name="session1" id="session1" value="<?php '.echo $_POST[ 'session1' ].'?>"><option value="" label=""</option>'; Any insight would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
p2grace Posted August 13, 2009 Share Posted August 13, 2009 You don't need to use the echo statement since it's already within a php string. Try this $session1 = mysql_real_escape_string($_POST[ 'session1' ]); $session1_popup = <<<HTML <select name="session1" id="session1" value="$session1"><option value="" label=""></option> HTML; Edit: I used heredoc in the code above. http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Quote Link to comment Share on other sites More sharing options...
fmpros Posted August 13, 2009 Author Share Posted August 13, 2009 Hey, thanks for the reply! I tried inserting the code exactly as shown below, with no luck. When the form returned an error, the field was reset and did not retain the original value. Any other ideas? Thanks again $session1 = $_POST[ 'session1' ]; $records1 = $result1->getRecords(); $session1_popup = <<<HTML <select name="session1" id="session1" value="$session1"><option value="" label=""></option> HTML; foreach($records1 as $record1) { $value1 = $record1->getField('_kf_workshop'); $label1 = $record1->getField('PHP_Workshop::Title'); $session1_popup.= '<option value="' . $value1 . '">' . $label1 . '</option>'; } $session1_popup.= '</select>'; Quote Link to comment Share on other sites More sharing options...
p2grace Posted August 13, 2009 Share Posted August 13, 2009 Oh, that's because we're trying to assign a value to a select box using php (can't be done). You have to write the script to loop through the options and highlight the correct option using selected="selected". Otherwise you can use an ajax library or jquery to do it. Quote Link to comment Share on other sites More sharing options...
fmpros Posted August 13, 2009 Author Share Posted August 13, 2009 That makes sense. I didn't know select boxes were so fickle. I'll give the loop a try. Thanks for pointing me in the right direction. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.