Current date in a form

I use form elements in my page including visitors select day, month, year options as a drop down menu. Can I display current date in that menu?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How are you constructing these form elements? Are they manually
created or are they being generated by a server side script?

Can you post a link to your form?

The short answer is yes, this is possible, and the longer answer
(how) depends on how you are creating them, and whether you require
this behavior to be standard for all users, or just nice-to-have for
those who have JavaScript enabled on their browsers.

Walter

On May 13, 2008, at 11:06 AM, agaksel wrote:

I use form elements in my page including visitors select day,
month, year options as a drop down menu. Can I display current
date in that menu?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

http://www.sarigermetasev.com/reservation.html

I created this page with FWP and used sendmail function with a .php processor


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How far ahead would you prefer that people book? Should they be
making their reservations a month or more in advance? If so, what I
would do is set the arrival date for one month from today, and the
departure date for arrival + 1 week (or whatever you would prefer for
a length of stay).

The universal way to do this would be in PHP, since it would be
available to everyone. Otherwise, you could do it in JavaScript,
understanding that visitors who have disabled JS would not get this
enhancement.

Here’s the PHP method I would follow. I am only showing one picker,
you will need to do this for each element of the date (day, month,
year) but you can re-use the core function that builds the picker.

First, change your page’s filename from reservation.html to
reservation.php using the Inspector.

Now, add this code into the Before HEAD part of the Page > HTML
Markup dialog.

http://pastie.caboo.se/196175

That gets you a nice reusable function which will make a picking list
out of an array. It sets the default option according to the current
value of a global variable, so the next thing you need to do is set
up the array(s) and the current value.

http://pastie.caboo.se/196182

(add the above code to your first set of <?php ?> delimiters, so it’s
all in the same block)

What this does is set up your days picker using the preferred arrival
date of one month from today.

You would then set up additional pickers for the month and year,
using the same basic technique. (N.B.: You can’t use range() to
create your array of days, it only works for numbers or sequential
letters, so you would have to use array
(‘Sunday’,‘Monday’,‘Tuesday’,‘Wednesday’,‘Thursday’,‘Friday’,‘Saturday’)
instead.)

Have a look at the PHP manual for the proper syntax to use in the date
() function to create your initial values for month and year. Be sure
to use the correct format string to show just the segment you want to
display when setting the default value.

Now, to display each picker inside your page, you would use a Markup
Item instead of a Freeway-drawn picker.

Click inside the table cell where you want the picker to appear. From
the main menu, choose Insert>Markup Item. In the code window that
appears, enter <?=$arrive_day_picker?> and okay the dialog. Preview
from your server, and you should see the current value of
$arrive_day_picker (a complete picking list of days, with the day one
month in the future selected) in place of this markup.

Repeat as needed for the other pickers, and you should be all set.

Walter

On May 13, 2008, at 12:11 PM, agaksel wrote:

http://www.sarigermetasev.com/reservation.html

I created this page with FWP and used sendmail function with a .php
processor


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry, just spotted a typo. Use this version instead:

http://pastie.caboo.se/196230

On May 13, 2008, at 1:32 PM, Walter Lee Davis wrote:

so the next thing you need to do is set
up the array(s) and the current value.

http://pastie.caboo.se/196182


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thank you Walter… I’ll try…


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Here’s another way you could try, using JavaScript. Please note that
this will take a bit of coercion in Freeway, since Freeway does not
add IDs to form elements for some reason. You will need to select
each form element in turn and use the Item > Extended dialog to add
the id property to each field. Once you have done this, the following
code will run correctly.

demo: http://www.walterdavisstudio.com/defaults.html

View Source to see the magic. There’s a whole load of extensions to
the Date object that allow it to do basic date math, and then some
functions that get re-used. Watch the comments, they explain where
things need to go in order to run correctly.

I mostly did this as an exercise to see how hard it would be to code
without resorting to Prototype. Man, did I miss that! Who in their
right mind would type:

elm.options[elm.options.selectedIndex].value

when there’s

$F('elm');

Walter

On May 13, 2008, at 3:41 PM, agaksel wrote:

Thank you Walter… I’ll try…


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter, your script is great… But… Please tell me, how can I use “_” mark for an item’s name (id) in Freeway? FW don’t use it. So, with Extend, use it only as “div id”, not item id… Just manuel in html file or Markup Item?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s easy. Just make sure you are in the right part of the
Inspector when you are trying to set it. Click on the Output tab
(looks like a tiny Web page) and then change the Name value there.
That’s what sets the name of the field. What you see on the Item tab
(left-most) is the (internal Freeway) name of the layout element that
contains the form field, labeled Title for some reason. You are
correct that Freeway will silently change that field to not contain
punctuation.

If you click on the form element (the Select) so that it is
highlighted with the 8 handles showing on corners and sides, and then
choose Item > Extended from the main menu, you will see three options
in the top of the dialog: < SELECT >, < div >, and < div style >.
Choose SELECT, and add your id by clicking New… and entering id and
your desired id in the name / value fields.

Walter

On May 15, 2008, at 12:39 PM, agaksel wrote:

Thanks Walter, your script is great… But… Please tell me, how
can I use “_” mark for an item’s name (id) in Freeway? FW don’t use
it. So, with Extend, use it only as “div id”, not item id… Just
manuel in html file or Markup Item?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ofcourse, I did all, before my last message… Than, I found what is wrong: Interesting… Problem’s source, my “Form Element Styler” action… When removed this action, solved… Everything OK now… Thanks again Walter…


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The problem you had with the id is that the ‘Form Element Styler’ action will set the id as to that of the item name and over ride what you enter in extended. If you leave the ‘Form Element’ Styler’ action in place you can then reference the item by using an id that is the item name from the Freeway inspector window.

HTH


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Just to clarify, the last reply was rushed:

If the ‘Form Element Styler’ action is applied to a form element then the action will be giving the item an id so you do not need to use Extended (if you do it will be ignored). The id that will be used for the element the action is applied to is the name that is in the Freeway inspector ‘Item’ field for that element.

Hope this is clearer.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The only issue with this is that the Item field won’t accept non-
alphanumeric characters, which leaves underscores etc. out.

Walter

On May 15, 2008, at 3:55 PM, Mike B wrote:

Just to clarify, the last reply was rushed:

If the ‘Form Element Styler’ action is applied to a form element
then the action will be giving the item an id so you do not need to
use Extended (if you do it will be ignored). The id that will be
used for the element the action is applied to is the name that is
in the Freeway inspector ‘Item’ field for that element.

Hope this is clearer.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I could never understand myself why Freeway does not permit
underscores and hyphens to be used in item names.

On May 15, 2008, at 10:21 PM, Walter Lee Davis wrote:

The only issue with this is that the Item field won’t accept non-
alphanumeric characters, which leaves underscores etc. out.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hyphens I do understand – they play havoc with JavaScript, since
they are ambiguously similar to the mathematical minus. But
underscores never hurt anyone, and they make search engines all warm
and tingly, so there’s really no good excuse for disallowing them.

Walter

On May 16, 2008, at 2:25 AM, Mike B wrote:

I could never understand myself why Freeway does not permit
underscores and hyphens to be used in item names.

On May 15, 2008, at 10:21 PM, Walter Lee Davis wrote:

The only issue with this is that the Item field won’t accept non-
alphanumeric characters, which leaves underscores etc. out.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options