Jump to content
Sign in to follow this  
HazMatt

JavaScript form submission hates my form

Recommended Posts

What I need is a JavaScript expert!

I already have server-side form validation running in my PHP code, but I have decided that I need client-side JavaScript validation because IE 7 and Firefox 3 both do not appear to save the contents of the webform when using the Back button to fix an incorrectly filled out form (Safari worked great).

I've found many fine examples of JavaScript form validation online, but they all seem to rely on the name attribute of a form field. Here's a typical example:

Email: 




FileMaker's PHP Site Assistant would generate the following code for an email field:


Email: 


NOTE:  This post appears to hide the PHP opening and closing tags!



The rendered PHP code would reveal something like this:


Email: 

The number 13 would indicate that it is the 13th field in the form; they are numbered (more or less) sequentially.

I can (and already have) used these rendered numbers in my server-side validation. But when I try to use the number value 13 or '13' or "13", my JavaScript function appears to be ignored and the form is sent to the server. Obviously JavaScript treats numbers differently than text names, and I don't know how to accommodate for that.

I would love to use the 'id' attribute in my JavaScript validations, but I haven't seen any examples that do so. I am also considering scrapping the Site Assistant generated code (only if I really have to) and hand-writing each field using the regular PHP API stuff, but I really just need to get this form live.

Thanks!

Edited by Guest

Share this post


Link to post
Share on other sites

Well I guess the FileMaker PHP Site Assistant is in violation of the W3C when it comes to generating name attributes:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

I fear I must further re-write the Site Assistant generated code to make things work properly. :P

Share this post


Link to post
Share on other sites

what you want is document.getElementById("theID")

each element should have a unique id; several elements can share the same name.










var field1 = document.getElementById("field1").value  









if you need for JavaScript to cast a number as a string just concatenate a null string to it



i.e.











    var answer = document.getElementById(42 + "").value



 

edited to add:

I am also considering scrapping the Site Assistant generated code (only if I really have to) and hand-writing each field using the regular PHP API stuff, but I really just need to get this form live.

From what I've seen of the site assistant's code, if you don't want exactly what it spits out building your own pages from scratch will save you tons of time in the end.

Edited by Guest

Share this post


Link to post
Share on other sites

Thanks for the reply Baloo. I did end up re-writing things from scratch to work the way I wanted, but the JavaScript tip is appreciated. I figured there'd have to be some way to do it!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • By SanderS
      I'm having great success with the PHP site assistant aside from one major issue. I'm not able to display images stored in Supercontainer. The code below will return a broken link. If I take the reference link and paste it into any web browser on any computer on any network, the link works fine. What obvious step am I missing?


      <td rowspan="8" class="field_data">
      <?php echo "<img src='http://74.119.147.179:80/SuperContainer/Files/CKD_Files/PDT/2009/1035/90101463440377643/IMG_6944.jpg' title='Error' alt='Error' />";?>
      </td>
×

Important Information

By using this site, you agree to our Terms of Use.