PHP Classes

Html entities in ONSUBMIT and ONSUBMITTING..

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Html entities in ONSUBMIT and...  >  (Un) Subscribe thread alerts  
Subject:Html entities in ONSUBMIT and...
Summary:Html entities in ONSUBMIT and ONSUBMITTING (bug?)
Messages:12
Author:ffff
Date:2007-07-07 14:01:32
Update:2007-07-11 02:00:03
 
  1 - 10   11 - 12  

  1. Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of ffff ffff - 2007-07-07 14:01:33
Hello again,

After playing more time with the class I found another thing which I do not know if it is a bug. What I am trying to do is to insert a custom javascript function when the form submits. I tries using the ONSUBMIT and ONSUBMITTING properties and I realized that the quotes ("") are converted to html entities...

So for example if I have this:

$form->ONSUBMIT='
var x=document.getElementById("element")';

In the browser it is displayed like this:

$form->ONSUBMIT='
var x=document.getElementById("element")';

I think this should be changed because inserting quotes in a javascript is necessary. I can not think of why would converting htmlentities in this case could be beneficial... If it is not a bug but a feature, how can I insert the quotes then?

  2. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of ffff ffff - 2007-07-07 14:23:11 - In reply to message 1 from ffff
For now I solved my problem by using single quotes ('').

Another thing I am noticing is that if my ONSUBMIT function returns false (so that the form is not submitted) when you try to submit the form again it asks you if you want to send the form again (but the form was never submitted).

For example:
1) the user fills out the form.
2) when the submit button is clicked, the ONSUBMIT javascript function is called.
3) the function does some extra validation (to see if the user can submit the form in that moment) and if not it returns false. the form is not submitted and the user gets a notice that he/she must make some changes.
4) the user makes the changes and hits the submit button again, then a message saying "this form was already submitted" is displayed.

I think this message should not be there...

  3. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-07 17:27:38 - In reply to message 1 from ffff
Encoding HTML entities is mandatory so the browsers do not take a quote in the middle of your Javascript code as if it is the end of the HTML attribute.

  4. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-07 17:37:09 - In reply to message 2 from ffff
When there is a validation error, the Javascript validation function generated by the class resets the form_submitted Javascript flag variable. So, it does not trigger the form submission alert.

If you are using the ONSUBMITTING event, do not make it return false ever, or else you may incur in that problem. ONSUBMITTING should not be used for validation.

  5. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of ffff ffff - 2007-07-07 18:20:58 - In reply to message 4 from Manuel Lemos
"If you are using the ONSUBMITTING event, do not make it return false ever, or else you may incur in that problem. ONSUBMITTING should not be used for validation."

So, where can I add a javascript that triggers in the 'onsubmit' of the form to allow or not to allow the form to submit?
What the my javascript code does is checking the value of an invisible input. If the value of the invisible input is 0, the form can not be submited. If the value is 1 the form can be submitted.
I tried specifying an invisible input in the form declaration and add the invisible input a "validate" function. But I think validate functions do not work with invisible inputs.

What are my options?

  6. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-07 19:26:55 - In reply to message 5 from ffff
There are not restrictions on performing validation on hidden inputs. It is a bit odd, but you can do it.

You can use the ValidationClientFunction to specify a function that should be called to validate that input on the browser side.

  7. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of ffff ffff - 2007-07-07 20:58:53 - In reply to message 6 from Manuel Lemos
OK, thank you. I will try it out.

It may sound odd to wish to validate a hidden input but here is the reason I need to do it:

I have a separate flash component that uploads an image and shows the image when it is done. I do not want users to be able to submit the form if they have not uploaded the image yet. So what I did is having a hidden input and when the image is uploaded the hidden input value is changed. Another solution would be integrating my component to the forms class as a plug-in but that I do not feel ready for that (I would have not clue how to do it).

For now, my solutions seems to work fine.

  8. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-07 21:27:42 - In reply to message 7 from ffff
Ok, it makes sense.

I tried once Flash components to do upload with a progress report bar, but I did not like the component that I found. It was starting uploading by itself and was not sending other form field values.

I wonder what kind of Flash component you are using. Did you write it, buy it, or it is Open Source?

  9. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of ffff ffff - 2007-07-08 00:50:22 - In reply to message 8 from Manuel Lemos
This one I wrote it. It is really cool and works very nice. The interface is built in flash; it is a little box with a button, when you click the button the "select file" prompt appears, and after the user selects the file, it starts uploading with a status bar. When the upload is finished the image is displayed in the box (thumbnail).

I have also used an open source one that works a little different (it has the flash file in the background) and the status bar is displayed with javascript. The URL is:

swfupload.mammon.se/

The advantage of that one is that it supports multiple uploads and the one I wrote is for a single upload.

I like the one I wrote for uploading pictures, and the other one for uploading any type of file.

I can mail you a link to a demo of the one I wrote If you want. In that case I would need your email address.



  10. Re: Html entities in ONSUBMIT and...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-08 01:29:36 - In reply to message 9 from ffff
Yes, I tried that but I did not like it because it is not useful for upload files along with other form values. Also it tries to upload files right after the users select the files.

The forms class already has a form upload progress custom input that shows a progress bar, but it relies on a PHP extension available on the server.

A Flash based solution would be more flexible as it would not rely on the server side extensions.

However, to be useful Flash based solutions should be able to fully replace all functionality of regular file inputs, i.e. when you submit the form, the form is submitted when the user uses the submit button, all other form field values are submitted with the file, and hopefully it can submit multiple files if the developer wants that.

If you have a Flash applet that can work like that, or could work like that with some additional work, it would be interesting if you could share it.

 
  1 - 10   11 - 12