PHP Classes

3 Forms on one page with no name

Recommend this page to a friend!

      Browser  >  All threads  >  3 Forms on one page with no name  >  (Un) Subscribe thread alerts  
Subject:3 Forms on one page with no name
Summary:I have 3 forms (ended with </form>) on one page.. inaccessible
Messages:5
Author:J Hart
Date:2010-06-16 05:05:04
Update:2010-06-29 03:26:53
 

  1. 3 Forms on one page with no name   Reply   Report abuse  
Picture of J Hart J Hart - 2010-06-16 05:05:04
I have 3 forms on one HTML page, each form begun with <form> and ended with </form>

When I've tried to use //form by itself I get an error because there are 3 forms found matching //form. Unfortunately when I attempt to use //form[2] I get the error that no such form can be found. I have not been able to figure out the syntax quite yet, and would appreciate any help you can offer.

here's the error from my php log file:

[16-Jun-2010 00:41:26] PHP Fatal error: Uncaught exception 'Exception' with message '3 forms found matching: //form' in /sysdude/bin/browser/browser.class.php:209
Stack trace:
#0 /sysdude/bin/browser/browser.addlistmember.php(73): Browser->getForm('//form')
#1 {main}
thrown in /sysdude/bin/browser/browser.class.php on line 209
[16-Jun-2010 00:59:36] PHP Fatal error: Uncaught exception 'Exception' with message '0 forms found matching: //form[2]' in /sysdude/bin/browser/browser.class.php:209
Stack trace:
#0 /sysdude/bin/browser/browser.addlistmember.php(73): Browser->getForm('//form[2]')
#1 {main}
thrown in /sysdude/bin/browser/browser.class.php on line 209

  2. Re: 3 Forms on one page with no name   Reply   Report abuse  
Picture of J Hart J Hart - 2010-06-20 04:41:02 - In reply to message 1 from J Hart
I used Firefox's Inspect elements feature to grab the XPath of the form, and plugged it into the getForm method. Unfortunately it still did not manage to pull up the correct form. The code looks like:


$b -> getForm ( "/html/body/table/tbody/tr/td/table[7]/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr/td/table[2]/tbody/tr[2]/td/form" )

Am I missing something in the syntax?

There are 3 un-named forms on the page, and I've attempted to use:
$b->getForm("//form")
and received
[20-Jun-2010 00:37:31] PHP Fatal error: Uncaught exception 'Exception' with message '3 forms found matching: //form'

I tried:
$b->getForm("//form[0]")
and received
[20-Jun-2010 00:38:47] PHP Fatal error: Uncaught exception 'Exception' with message '0 forms found matching: //form[0]'

I tried:
$b->getForm("//form[1]")
and received
[20-Jun-2010 00:39:29] PHP Fatal error: Uncaught exception 'Exception' with message '3 forms found matching: //form[1]'

and lastly I tried:
$b->getForm("//form[2]")
and received
[20-Jun-2010 00:39:56] PHP Fatal error: Uncaught exception 'Exception' with message '0 forms found matching: //form[2]'

Any help would be appreciated!

  3. Re: 3 Forms on one page with no name   Reply   Report abuse  
Picture of Jon Gjengset Jon Gjengset - 2010-06-20 09:43:20 - In reply to message 2 from J Hart
Hmm.. That's really strange, //form[2] should work if it is the last form you want..

You could try "//form[last()]" or "//form[position() = 2]" instead, and see if that makes a difference.. Alternately, I would try to find something else to distinguish the node with. Maybe:
"//table//table//table//table//table//td/form"
Although it's ugly, it might be that there is some quirk with XPath node positioning predicates in the PHP implementation..

Jon

  4. Re: 3 Forms on one page with no name   Reply   Report abuse  
Picture of Jon Gjengset Jon Gjengset - 2010-06-26 08:30:34 - In reply to message 3 from Jon Gjengset
Did you resolve this, or do you still have the problem?

  5. Re: 3 Forms on one page with no name   Reply   Report abuse  
Picture of J Hart J Hart - 2010-06-29 03:26:53 - In reply to message 4 from Jon Gjengset
Unfortunately no, I have tried to come up with an Xpath which would access the first or second forms on the page, but have had absolutely no luck. I thought perhaps that it came down to the version of PHP I'm running. I tried it on php 5.2.8 and on 5.3.1 both with the same result (error in my php_errors log indicating there are 3 forms matching).