By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,685 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,685 IT Pros & Developers. It's quick & easy.

submit form...created with php

P: n/a
I know this isn't a php group but I was wondering if my problem is with my
javascript in my php code. I'm debugging someone else's code and I can't
figure out why this form won't submit.

This code doesn't do anything:
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go onclick=document.formx3.action='".$var1."';
document.formx3.submit();></form>";
?>

This code works, but I want to know why the above code doesn't.
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx2' action='".$var1."'><input type='text'><input
type=button value=go onclick=document.formx2.submit();></form>";
?>

It seems awful weird to even try to assign the forms action and then submit
it all in the onclick event...are you allowed to do this in Javascript?

Thanks in advance...
-Bruce
Jul 23 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
In article <10*************@corp.supernews.com>,
bruce~w~duncan@~hotmail.com enlightened us with...
I know this isn't a php group but I was wondering if my problem is with my
javascript in my php code. I'm debugging someone else's code and I can't
figure out why this form won't submit.

When you are debugging a server-side app and think it's the client-side
script, your best bet is to view the html source of the rendered doc to
see if you got what you thought you should get. I've cought many an
eaten quote that way. ;)

It isn't working because you are missing quotes that are required for
compound onClick.
This code doesn't do anything:
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go onclick=document.formx3.action='".$var1."';
document.formx3.submit();></form>";
?>
The onClick, rendered (view->source), should look like this.
onclick="document.formx3.action='someAction';docum ent.formx3.submit();">

Note the double quotes that you don't have because your PHP would eat
them. I don't remember the exact way to escape double quotes in PHP, but
assuming it is a backslash, it would look like this in PHP.

echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go onclick=\"document.formx3.action='".$var1."';
document.formx3.submit();\"></form>";

It seems awful weird to even try to assign the forms action and then submit
it all in the onclick event...are you allowed to do this in Javascript?


Yup.
Most of us put compound actions in functions and call those, though, for
ease of modification later.
--
--
~kaeli~
You feel stuck with your debt if you can't budge it.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
kaeli wrote:
Note the double quotes that you don't have because your PHP would eat
them. I don't remember the exact way to escape double quotes in PHP, but
assuming it is a backslash, it would look like this in PHP.

echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go onclick=\"document.formx3.action='".$var1."';
document.formx3.submit();\"></form>";


Both from a J(ava)Script and a PHP hackers point of view, this is a
Bad Thing. As for PHP: Double quotes enforce expansion of variable
references, so if there are none within the string they are highly
inefficient. And as for J(ava)Script, I don't see the necessity of
using (here) error-prone client-side scripting at all. Consider
this instead:

<?php
...
?>
<form action="<?php echo $var1; ?>" name="formx3" method="post">
<input>
<input
type="submit"
value="go">
</form>
<?php
...
?>
PointedEars
Jul 23 '05 #3

P: n/a
In article <10*************@corp.supernews.com>, Bruce Duncan says...
I know this isn't a php group but I was wondering if my problem is with my
javascript in my php code. I'm debugging someone else's code and I can't
figure out why this form won't submit.

This code doesn't do anything:
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go onclick=document.formx3.action='".$var1."';
document.formx3.submit();></form>";
?>

This code works, but I want to know why the above code doesn't.


It's probably because by the time it gets to the browser it's
incorrectly formed.

Your code outputs this as the onclick:
onclick = document.formx3.action='something'; document.formx3.submit();

It should be something like this:
onclick = "document.formx3.action='something'; document.formx3.submit()"

--
Hywel I do not eat quiche
http://kibo.org.uk/
http://kibo.org.uk/mfaq.php
Jul 23 '05 #4

P: n/a

try as follows
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go document.formx3.action='".$var1."';
onclick=document.formx3.submit();></form>";
?>
the action must be defined before onclick I think
i have not tried myself
bye
--
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr

http://forums.club-internet.fr/
Jul 23 '05 #5

P: n/a
Dominique wrote:
try as follows
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'><input type='text'><input
type=button value=go document.formx3.action='".$var1."';
onclick=document.formx3.submit();></form>";
?>
the action must be defined before onclick I think


Correct, a "form" element without a defined "action" attribute is invalid
HTML. But AFAIS there is no client-side J(ava)Script required at all.
PointedEars
Jul 23 '05 #6

P: n/a
MJ
> the action must be defined before onclick I think
i have not tried myself


Actually, that's not true. I often define the action (based on conditions)
after the onclick. However, usually I use a function like:

<script>
function Submit_form(){
if
(document.form.category.options[document.form.category.selectedIndex].value
== "option1"){
document.form.action = "whatever1.php"; // Define the action
document.form.submit(); // Submit the page
return true;
} else if
(document.form.category.options[document.form.category.selectedIndex].value
== "option2"){
document.formSearch.action = "whatever2.php";
document.formSearch.submit(); // Submit the page
return true;
} // and so on...
}
</script>

<input name="Search" type="button" id="Search" value="Search"
onClick="return Submit_form();">

Works like a charm. I think the original poster's problem was improperly
formated code (lack of proper quotes). His onclick code was:

onclick=document.formx3.action='".$var1."'; document.formx3.submit();

Should have been:

onclick=\"document.formx3.action='".$var1."';docum ent.formx3.submit();\"

the quotes are escaped for PHP.
Jul 23 '05 #7

P: n/a
MJ wrote:
the action must be defined before onclick I think
i have not tried myself


Actually, that's not true. I often define the action
(based on conditions) after the onclick. [...]


So you are creating invalid HTML and/or create forms that are useless for
users without client-side J(ava)Script and will malfunction for some with
client-side J(ava)Script (as the "action" is either not changed or not
changed fast enough).
PointedEars
Jul 23 '05 #8

P: n/a
MJ
> So you are creating invalid HTML and/or create forms that are useless for
users without client-side J(ava)Script and will malfunction for some with
client-side J(ava)Script (as the "action" is either not changed or not
changed fast enough).
PointedEars


It's only invalid HTML under outdated W3C standards written 7 years ago.
All versions from the past four years of the most popular browsers (IE,
Netscape, Opera, Mozilla) support doing this. I have never heard of any
sort of "malfunction" on the client side. I know several extremely high
traffic web sites that use similar functions.

Who doesn't have client-side Javascript these days? I'm sure less than one
half of one percent of all users. If they have Javascript turned off,
that's their tough luck. If their systems don't support Javascript, they
need to update their computers. My sites aren't intended for people with
386's running Windows 3.1.
Jul 23 '05 #9

P: n/a
"MJ" <no*****@thank.you> writes:
Who doesn't have client-side Javascript these days?
Statistics differ. They usually put the number at, or just above, 10%
of users. I see now that TheCounter.com has dropped sharply to around
5% at the beginning of the year, suggesting they changed their method
of disvocering Javascript availability. We still don't know what that
method is. Statistics are ... well, statistics (as in "lies, damn
lies, and ..."). It's also all we have.
I'm sure less than one half of one percent of all users.
Based on intuition or any actual research?
If they have Javascript turned off, that's their tough luck.
Not if it's a commercial site. Then it's the competition's luck. Or
the ADA (or similar other-nationality legislation) litigation lawyers'
luck
If their systems don't support Javascript, they need to update their
computers.
Their handheld computers or mobile phones might not be upgradeable.
They are also likely to be more current than any version of Internet
Explorer.
My sites aren't intended for people with 386's running Windows 3.1.


That's your decission. Not a decission I would expect from a competent
web developer, though, as it doesn't take that much extra work to make
pages *usable* without Javascript. After all, the most important part
of a page *is* the content.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #10

P: n/a
On Mon, 31 May 2004 14:37:33 +0200, Lasse Reichstein Nielsen wrote:
....
...After all, the most important part
of a page *is* the content.


I prefer to think of it like this..

There are three important things
to a web-site, they are
- quality of content
- content usability/accessibility
- volume of content
( In no particular order )

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #11

P: n/a
MJ
I'm sure less than one half of one percent of all users.
Based on intuition or any actual research?


Actual research. Over 99% of users use Javascript compatible browsers. If
TheCounter.com is reporting 5%, more than 4% of that is people who have
Javascript turned off.
If they have Javascript turned off, that's their tough luck.
Not if it's a commercial site. Then it's the competition's luck. Or
the ADA (or similar other-nationality legislation) litigation lawyers'
luck


At this time web sites are not required to conform to the ADA, although a
few people have brought court cases, nobody has won yet. Even if the ADA
did apply, it states that businesses only have to make a reasonable
accomidations. Redesigning a site to ADA standards would be too costly and
take too many man hours for many commercial sites.
If their systems don't support Javascript, they need to update their
computers.


Their handheld computers or mobile phones might not be upgradeable.
They are also likely to be more current than any version of Internet
Explorer.


Most sites that support mobile phones and handhelds design specific versions
of their sites for those devices.
My sites aren't intended for people with 386's running Windows 3.1.


That's your decission. Not a decission I would expect from a competent
web developer, though, as it doesn't take that much extra work to make
pages *usable* without Javascript. After all, the most important part
of a page *is* the content.


Judging by the majority of sites on the Net, competent web developers are
few and far between. The most important part is giving your visitors what
they want. Developing a stripped down versions of sites to please less than
1% of visitors is a waste of time and resources that could be put to better
use. Technology can't move forward if everyone is trying to support
outdated and obsolete systems and software. In almost any business this is
the case. The recording industry doesn't produce LPs anymore because they
have become outdated and obsolete, even though many people still have
turntables. Losing less than 1% of my visitors to a competitor's site
doesn't bother me, because I'm gaining exponentially more customers by
having a much better site than my competitors.
Jul 23 '05 #12

P: n/a
MJ
At this time web sites are not required to conform to the ADA, although a
few people have brought court cases, nobody has won yet. Even if the ADA
did apply, it states that businesses only have to make a reasonable
accomidations. Redesigning a site to ADA standards would be too costly and take too many man hours for many commercial sites.


Correction: The ADA can apply to web sites, but reasonable accommodations
and spending thousands of dollars to tens of thousands of dollars to make a
site ADA compliant really isn't a reasonable accommodation, unless your
company is making a sizable chunk of profit every year.
Jul 23 '05 #13

P: n/a
MJ wrote:
I'm sure less than one half of one percent of all users.

0,5% may still be huge for a successful website.
Developing a stripped down versions of sites to please less than
1% of visitors is a waste of time and resources that could be put to better
use.
I agree with this, however this is not the point here, if I may explain.

There are probably more than 100 browsers available on the net, offering
different scripting capabilities. As a result, the approach to
programming is very particular and differs considerably from usual
programming, in a known environment. In fact, it's likely that any code
will fail on at least one platform (and of course not even mentioning
javascript-disabled ones).

Therefore, the general conception should be adapted, and it's being more
and more accepted that scripting should be made on a two-layers' model:
- first building a usable website, with simple HTML. This is what your
visitors will get if the scripts do not work (or if javascript is disabled),
- then *adding* the javascript, transforming the HTML and adding
functionalities - taking advantage of the unique javascript capability
to determine, at run-time, whether the script will be supported, and if
not, cleany degrading to the already existing HTML.

As you can see, this simple model also applies to the "old" user agents
you mention, since they'll be given the already usable HTML, which they
can interpret correctly.

You've previously given an example of setting a form action. Why don't
you use something like

<form action="defaultAction"
onsubmit="return setAppropriateAction(this)">
<input type="submit">
</form>

which will work even if js is disabled (you just have to handle the form
server-side if the script fails, as you probably already do as it's
trivial for a user to trick a client-side script at run-time). Such a
construct doesn't introduce a dependency on javascript and works exactly
the same.
Losing less than 1% of my visitors to a competitor's site
doesn't bother me, because I'm gaining exponentially more customers by
having a much better site than my competitors.


That may be fair (although I doubt such things can be accurately
measured) but the point is that you certainly don't have to waste these
1% customers, it's actually a conception issue, you're (IMHO) applying a
wrong conception when using javascript, which makes you lose clients
while it'd be easy to not lose them.

Now there are of course situations in which you know your environments,
like intranets, in which case the general conception can be a bit
different that the one exposed above.
Regards,
Yep.
Jul 23 '05 #14

P: n/a
On Mon, 31 May 2004 07:46:44 -0700, "MJ" <no*****@thank.you> wrote:
Based on intuition or any actual research?
Actual research. Over 99% of users use Javascript compatible browsers.


Rubbish, possibly the majority of browsers in the world are not script
enabled (the ones shipped with the majority of mobile phones) Of
course they're rarely used, especially on sites that TheCounter uses.
If
TheCounter.com is reporting 5%, more than 4% of that is people who have
Javascript turned off.
Right... and they use statistically representative sample because?
Not if it's a commercial site. Then it's the competition's luck. Or
the ADA (or similar other-nationality legislation) litigation lawyers'
luck


At this time web sites are not required to conform to the ADA, although a
few people have brought court cases, nobody has won yet. Even if the ADA
did apply


Remember he said or similar other nationality.
Redesigning a site to ADA standards would be too costly and
take too many man hours for many commercial sites.
Ooops! Unfortunately that defence didn't work in SOCOG-Maguire and
won't elsewhere, simply because it's patently not true, and there are
of lots of genuine experts capable of standing up in court and saying
it.
Judging by the majority of sites on the Net, competent web developers are
few and far between. The most important part is giving your visitors what
they want. Developing a stripped down versions of sites to please less than
1% of visitors is a waste of time and resources that could be put to better
use.
Have you ever read the group? Have you ever seen any mention of
creating stripped down websites as the solution other than as a
strawman?
The recording industry doesn't produce LPs anymore because they
have become outdated and obsolete, even though many people still have
turntables.
completely irrelevant, but last year the vinyl market was larger than
the year before...
Losing less than 1% of my visitors to a competitor's site
doesn't bother me, because I'm gaining exponentially more customers by
having a much better site than my competitors.


Except of course, he chose to employe competent techniques, and his
site not only works without javascript, but is also more visible to
google, and works for all his customers.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #15

P: n/a
MJ
Actual research. Over 99% of users use Javascript compatible browsers.


Rubbish, possibly the majority of browsers in the world are not script
enabled (the ones shipped with the majority of mobile phones) Of
course they're rarely used, especially on sites that TheCounter uses.


Hmmm, somebody can't read. What does that say up there? "99% of users USE
Javascript compatible browsers". Not the majority of browsers in the world
are script enabled. Who cares if the majority of cell phone browsers don't
support Javascript. The majority of cell phone browsers are NEVER used.
If
TheCounter.com is reporting 5%, more than 4% of that is people who have
Javascript turned off.


Right... and they use statistically representative sample because?
Not if it's a commercial site. Then it's the competition's luck. Or
the ADA (or similar other-nationality legislation) litigation lawyers'
luck


At this time web sites are not required to conform to the ADA, although a
few people have brought court cases, nobody has won yet. Even if the ADA
did apply


Remember he said or similar other nationality.


International lawsuits regarding accessibility are going to be EXTREMELY
rare if they ever happen at all and they are extremely hard for the
plaintiff to win unless you actively market to the specific country that the
unhappy visitor is in.
Redesigning a site to ADA standards would be too costly and
take too many man hours for many commercial sites.


Ooops! Unfortunately that defence didn't work in SOCOG-Maguire and
won't elsewhere, simply because it's patently not true, and there are
of lots of genuine experts capable of standing up in court and saying
it.


Now who's talking rubbish. For every "genuine expert" that says one thing
there's another "genuine expert" who says the complete opposite. It all
depends on what your web site offers. Interactive, multimedia rich sites
can be next to impossible to conform to such accessibility standards. If
the site is mostly text based content, then sure, making it accessible is
much easier. It also depends on the size of the site.
Losing less than 1% of my visitors to a competitor's site
doesn't bother me, because I'm gaining exponentially more customers by
having a much better site than my competitors.


Except of course, he chose to employe competent techniques, and his
site not only works without javascript, but is also more visible to
google, and works for all his customers.


I have no problem with my visibility in Google (I rank higher than the
majority of my competitors) or any other search engines. The competitors'
sites may have been created with "competent techniques" as defined by a 7
year old document, but their sites are static, uninteresting, horribly
designed, and not very useful. That's not just my opinion. I have heard it
many, many times from people who have migrated to my business. My
competitors are losing customers because they hasn't updated their sites to
what today's customers want. My business is booming while several of my
competitors have gone under. Since adding more interactive features with
Javascript, Flash, etc. my numbers have spiked even more.

By the way, you act as if I said that my sites are 100% javascript. They
are still accessible by non-javascript enabled browsers, but some features
might not be completely functional as they were intended. I use Javascript
mostly for client-side form validation which is then run through server-side
validation as well. Menus have rollovers that work fine with non-javascript
browsers. I test my sites thoroughly with many different browsers.

So, go ahead and follow your 7 year old W3C HTML standards as strictly as
you can. I'm sure you have it all printed out, nicely bound, in a
protective sleeve, and under your pillow. You are obviously a follower,
while others of us choose to drive. Those who drive tend to get ahead while
others play catch-up. Now, if you'll excuse me, I've got a ton of web
customers to assist.
Jul 23 '05 #16

P: n/a
On Mon, 31 May 2004 10:02:32 -0700, "MJ" <no*****@thank.you> wrote:
>At this time web sites are not required to conform to the ADA, although a
>few people have brought court cases, nobody has won yet. Even if the ADA
>did apply
Remember he said or similar other nationality.


International lawsuits regarding accessibility are going to be EXTREMELY
rare if they ever happen at all and they are extremely hard for the
plaintiff to win unless you actively market to the specific country that the
unhappy visitor is in.


This is an international group, do not give legal advice based on your
regional prejudices, if you're going to give advice saying "use
javascript" the ADA doesn't apply (even though you later concede it
does) then preface this with "if in the USA"
Ooops! Unfortunately that defence didn't work in SOCOG-Maguire and
won't elsewhere, simply because it's patently not true, and there are
of lots of genuine experts capable of standing up in court and saying
it.


Now who's talking rubbish. For every "genuine expert" that says one thing
there's another "genuine expert" who says the complete opposite.


Unlikely - and remember you're defending this in a court, with a poor
blind kid in the dock, and persuasive sounding experts (and the cheap
to do, will be standing up for free, you'll be paying your experts
lots of cash to be there)
Interactive, multimedia rich sites
can be next to impossible to conform to such accessibility standards.
Of course they can, look if you're going to talk about accessibility
standards, _please_ learn about them, captioning a 3 hour video is not
reasonable accommodation, but loads of other stuff is.
I have no problem with my visibility in Google (I rank higher than the
majority of my competitors) or any other search engines.


URL, if you're so proud?

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #17

P: n/a
MJ wrote:

Who wrote that? Please provide proper
attribution as recommended in RFC 1855.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
So you are creating invalid HTML and/or create forms that are useless for
users without client-side J(ava)Script and will malfunction for some with
client-side J(ava)Script (as the "action" is either not changed or not
changed fast enough).
[...]
It's only invalid HTML under outdated W3C standards written 7 years ago.


This is utter nonsense and you know that.
All versions from the past four years of the most popular browsers (IE,
Netscape, Opera, Mozilla) support doing this.
If so, what about all the others?
I have never heard of any sort of "malfunction" on the client side.
That does not mean there is none. Do you really expect every annoyed
visitor/customer to complain explicitely? They tell their friends,
colleagues and family that this site is junk and you have not only
one, but probably more customers/visitors less without knowing it.
I know several extremely high traffic web sites that use similar functions.
So people should eat sh*t instead because a billion flies cannot be wrong?
Who doesn't have client-side Javascript these days?
I sometimes have. Surprised?

But you do have read that it does not need to work (as supposed) even if
J(ava)Script is present and enabled, don't you? It is a DOM and timing
problem discussed several times before. To know of problems and to ignore
them anyway is not a behavior I would expect from a competent author.
[unfounded assumptions about who uses what]


That's ridiculous. But, after all, what to expect from a OjE user with
a faked From ...
PointedEars
Jul 23 '05 #18

P: n/a
JRS: In article <r7**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Mon, 31 May 2004 14:37:33 :
After all, the most important part
of a page *is* the content.


But the really most important property, IMHO, is that the page should
not jam or crash any browser or its operating system.

There is an accessibility tester that does that to my machine. And, on
a newer machine, it by default produces a large table in tiny writing
with the error reports buried deep therein. Should an accessibility
tester be accessible?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #19

P: n/a
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Mon, 31 May 2004 22:03:12 :
Who wrote that? Please provide proper
attribution as recommended in RFC 1855.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv


To which part of RFC1855 do you refer?

I have here FYI28/RFC1855 dated October 1955; if you are referring to
any other version (AIUI, there will be none), then you have been hoisted
by your own petard.

The only reference to attribution therein is specifically for Mail, and
does not describe "proper attribution".

Please verify references *before* giving them.


Son-of-RFC1036 (1994) does refer to "attribution lines" containing more
than just a name. Note the implication that more than one line may be
needed.

A draft RFC by C H Lindsey ( a well-known News expert), dated August
2002, envisages a line containing name, E-address, newsgroup, Message-
ID, date, and time; and that it may be folded. It is called draft-ietf-
usefor-article-08.txt

Therefore, your customary tedious insistence on minimal attributions is
contrary to recent thinking.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.