Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with buttons

Participant ,
Mar 03, 2008 Mar 03, 2008
I have a form with the following three buttons. Originally, the back and home buttons were images with an a hef tag, and the second button submitted the form to an action page, after javascript edits. So I am mixing buttons and images, and everything works fine.

I have been told to do away with the images and make everything buttons, so I named the three buttons 1, 2, and 3 and sent everything to my action page, and did a cfif isdefined for each button, then did a cflocation url to pass to the apppropriate pages. That works ok.

But is there a way to do it without sending the first and third buttons to the action page, and only send the second one ?

This is what I have so far. The back button works, the second button still submits and validates, but I do not know how to code the third button, which should take me to the page index.cfm, when I click on it.

What is the proper syntax for this ? Thanks

<td align="center">
<INPUT TYPE="button" name="button_1" VALUE=" Back " onClick="history.go(-1)">

</td>

<td align="center">
<input type="button" name="button_2" value=" Upload File " onClick="validateForm(document.upload_form)">
</td>

<td align="center">
<input type="button" name="button_3" value=" Home " onClick="index.cfm">
</td>
502
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2008 Mar 03, 2008
onclick="window.location.href='index.cfm'

but... what happens if your user has js disabled?
replying heavily on client-side scripting is gonna get you in trouble...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2008 Mar 03, 2008
Thanks Azadi for your response.

If they do have js disabled, what would you suggest the best way to do this ? Back to my original method of sending all the buttons to the action page and then redirect with cflocation url ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 04, 2008 Mar 04, 2008
quote:

Originally posted by: trojnfn
Thanks Azadi for your response.

If they do have js disabled, what would you suggest the best way to do this ? Back to my original method of sending all the buttons to the action page and then redirect with cflocation url ?

Alternatively, you could put your buttons inside anchor tags.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2008 Mar 03, 2008
yep, that will guarantee the buttons (and other parts of your form)
works as you intend it to.

as a rule, ALWAYS use server-side validation and processing. add in
client-side for added user experience and 'prettiness' - never rely on
client-side 100%.

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 05, 2008 Mar 05, 2008
Hello Azadi,

I wanted to make my error messages consistent, like the popup when I use required=yes message, for cfinput.
For the error validation on the server side, I do something like this :
<cfif qry.recordcount eq "0">
<cflocation url="front_page.cfm?coming_from_screen="action_page">
</cfif>

Then back in the front page, I check for the url, then
<cfif coming_from_screen is "action_page">
<script>
alert("not records found">
</script>
</cfif>

This seems to work ok, since it is doing the edit/validation when submitted, then displaying the error message back on the front page.

The only problem is that it wipes out all the entries when the error message is displayed. Is there a way to keep what was already typed in, on the screen, when the error message is returned ?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 05, 2008 Mar 05, 2008
the way i do it is:

a) <cfparam> each and every form var used on the page: if it's an
'insert/add' page - cfparam then to default values you need; on an
'update/edit' page cfparam them to values returned by the query taht
pulls the data to be edited from the db. it get a little bit trickier
with radio buttons/checkboxes/file uploads, but nothing too tricky.

b) each form field on the page has a value set to same name
#form.formfield#, i.e. <input type='text' name='fname'
value='#form.fname#'> - since i cfparam all of them, these FORM scope
vars are available to me even without submitting the form.

c) validate some form data on the client side using custom js and/or
cform's required attribute validation

d) validate all form data for value required and data format on the
server using cfif/cfelse and/or cfswitch/cfcase logic as necessary. i
usually set an err var (i.e. <cfset err = 0>) and errmsg var (i.e.
<cfset errmsg = "">) BEFORE the validation code block, then if a form
field does not validate i cfset err = 1 and errmsg = errmsg & "some text
about this error;<br />". then my db inserts/updates are inside a cfif
block which checks that err = 0.

e) in my from i have another cfif block that checks for err gt 0 and if
so cfoutputs #errmsg#. since all form fields have value set to their
value as described in b) above, all data posted by user is preserved in
the form. with file upload fields i usually do file upload only if
server-side form data validation succeeds; a user has to re-select a
file if form does not validate which is not too much of an
inconvenience, especially if you remind the user in your error message
to re-select the file...

now, the above is not a perfect solution, and in other cases may be an
overkill. this is just something i do. i could have forgotten to mention
something since it is pretty late here and i am rather tired. if i do
remember it tomorrow i will post more...

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2008 Mar 03, 2008
That actually works.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2008 Mar 05, 2008
Hi trojnfn,

Try this code <input type="button" name="button_3" value=" Home " onClick="location.href='index.cfm';">

instead of your following code

<input type="button" name="button_3" value=" Home " onClick="index.cfm">

Hope this will works for you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2008 Mar 06, 2008
LATEST
Do you have this sorted yet? If not PM me and i'll be happy to help you out.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources