Re: Elegance is the goal... Sticky form submit help
| From: | Jason Pruim | Date: | Sat, 11 Sep 2010 17:14:58 +0000 |
| Subject: | Re: Elegance is the goal... Sticky form submit help | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307958@lists.php.net to get a copy of this message | ||
Hi Tamara,
On Sep 11, 2010, at 12:39 PM, Tamara Temple wrote:
Rather than repeating all that code, I suggest the following: <select name="type" id="type> <option value="0">-- select type --</option> <option value="meeting" <?php echo (isset($_POST['hidSubmit'] && $_POST['hidSubmit'] == TRUE && $_POST['type'] == "meeting") ? "selected" : '' ?> <option value="event" <?php echo (isset($_POST['hidSubmit'] && $_POST['hidSubmit'] == TRUE && $_POST['type'] == "event") ? "selected" : '' ?> </select>That's actually what I'm trying to get away from. I was hoping to do it all in HEREDOC syntax. I've always thought it made it cleaner. But that is a personal opinion :)
For a month selector, try: <?php // assume current month number is in $curr_month $months = array(1 => "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); // will create an array of month names, with a starting base of 1 (instead of zero) echo "<select name=\"month\" id=\"month\">\n"; foreach ($months as $m => $mname) { echo "<option value=\"$m\""; if ($curr_month == $m) echo " selected "; echo ">$mname</option>\n"; } echo "</select>\n"; ?> There are other possiblities as well. One time, I didn't want to actually store the month names, perhaps allowing them to be localized. Instead I used strftime, which will return appropriate names based on locale: <?php // assume current month number is in $curr_month echo "<select name=\"month\" id=\"month\">\n"; for ($m = 1; $m <= 12; $m++) { echo "<option value=\"$m\""; if ($curr_month == $m) echo " selected "; echo ">"; $mname = strftime("%B", 0,0,0,2010, $m, 1); // time, year and day don't matter, all we're after is the appropriate month name set in the locale echo $mname; echo "</option>\n"; } echo "</select>\n"; ?>I'm actually doing something similar to that right now... <?PHP if (isset($_POST)) { $date = date("n", $i); echo $date; $i++; } ?> Prints just the numeric reference to the month.