Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old September 2nd, 2003, 06:40 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Problems with form fields (and Javascript?)

I have two related(?) problems. I have the "typical" self-validating page where it includes a form which posts back to the page on submittal. It also has the if (isset($HTTP_POST_VARS["submit_name"])) line that leads into the form validation. The form has a submit button with name="submit_name" and a few input/text fields such as "input1", "input2", etc.

Problem #1: I'm having some problems with getting form fields sent to the server when using Javascript's document.form.submit(). When I use the submit button to directly post to the validation, $HTTP_POST_VARS["submit_name"] is defined as are all the input fields. However, when I use document.form.submit(), only the input fields are defined. The submit_name isn't. Therefore, the initial isset() on the form submit_name fails and there's no validation done.

Problem #2: The form has some fields which are dependent on other user inputs. The user selects an item from a list which then changes a calculation elsewhere on the field. When I submit the form, I'm only getting the user-modified fields and none of the dependent ones. Javascript is used to make the field alterations during an onchange action.

Reply With Quote
  #2  
Old September 2nd, 2003, 06:51 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Problems with form fields (and Javascript?)

image, and submit type fields are only sent if you press them, so no, if you use javascript.

but you can put a hidden field of name "submit_name" that will be sent regardless of the method...

Reply With Quote
  #3  
Old September 2nd, 2003, 07:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Problems with form fields (and Javascript?)

Great - that "solves" problem #1. Is there a site that gives this sort of information instead of php.net? php.net just lists what the global variables are but nothing like what you just mentioned. And most form tutorials just give the self-validation example.

Now, what about problem #2? For a bit more help, here's a pseudo snippet (the real code's inaccessible at the moment).

php Code:
Original - php Code
  1. <script>
  2. js_update2()
  3. {
  4. // make field2 = field1+1 (the real calculation is more complicated)
  5. document.formX.field2.value = parseInt(document.formX.field1.value) + 1;
  6. }
  7. </script>
  8. <?php
  9. if (isset($HTTP_POST_VARS["sub_btn"])) {
  10.  ...
  11. } else {
  12. <form name=formX action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>">
  13. <input type=text name="field1" onChange=js_update2() value="0">
  14. <input type=text name="field2" value="1">
  15. <input type=submit name="sub_btn">
  16. </form>
  17. }


When I hit the sub_btn after making a change to field1 (and through the javascript, field2), I get $HTTP_POST_VARS["field1"] but not $HTTP_POST_VARS["field2"].

Reply With Quote
  #4  
Old September 2nd, 2003, 11:21 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Problems with form fields (and Javascript?)

there are several things missing/bad in your code sample..

but this works for me. i change first field to 7 and click submit, and get 8 in the second field in php...

php Code:
Original - php Code
  1.  
  2. <script>
  3. function js_update2()
  4. {
  5. // make field2 = field1+1 (the real calculation is more complicated)
  6. document.formX.field2.value = parseInt(document.formX.field1.value) + 1;
  7. }
  8. </script>
  9. <form method=post name=formX action="info">
  10. <input type=text name="field1" onChange="js_update2()" value="0">
  11. <input type=text name="field2" value="1">
  12. <input type=submit name="sub_btn">
  13. </form>


Reply With Quote
  #5  
Old September 3rd, 2003, 01:05 AM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Problems with form fields (and Javascript?)

How about this? This works for me too!
php Code:
Original - php Code
  1.  
  2. <?
  3. // test.php
  4. echo "Field1 :".$field1;
  5. echo '<br>Field2 :'.$field2;
  6. ?>
  7. <html>
  8. <head>
  9. <title>Test Page</title>
  10. <SCRIPT LANGUAGE="JavaScript">
  11. function js_update()
  12. {
  13. document.formX.field2.value = parseInt(document.formX.field1.value) + 1;
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <form name=formX method=post action="test.php">
  19. <input type=text name="field1" value="0" onKeyUp="js_update()">
  20. <input type=text name="field2" value="1">
  21. <input type=submit name="sub_btn">
  22. </form>
  23. </body>
  24. </html>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Problems with form fields (and Javascript?)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway