473,770 Members | 5,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

submit form...created with php

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'><in put
type=button value=go onclick=documen t.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'><in put
type=button value=go onclick=documen t.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
19 2169
In article <10************ *@corp.supernew s.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'><in put
type=button value=go onclick=documen t.formx3.action ='".$var1."';
document.formx3 .submit();></form>";
?>
The onClick, rendered (view->source), should look like this.
onclick="docume nt.formx3.actio n='someAction'; document.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'><in put
type=button value=go onclick=\"docum ent.formx3.acti on='".$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
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'><in put
type=button value=go onclick=\"docum ent.formx3.acti on='".$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
In article <10************ *@corp.supernew s.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'><in put
type=button value=go onclick=documen t.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='someth ing'; document.formx3 .submit();

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

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

try as follows
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'>< input type='text'><in put
type=button value=go document.formx3 .action='".$var 1."';
onclick=documen t.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
Dominique wrote:
try as follows
<?PHP
$var1 = "http://localhost/php/index.php";
$varx = "bruce";
echo "<form name='formx3' method='post'>< input type='text'><in put
type=button value=go document.formx3 .action='".$var 1."';
onclick=documen t.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
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.option s[document.form.c ategory.selecte dIndex].value
== "option1"){
document.form.a ction = "whatever1.php" ; // Define the action
document.form.s ubmit(); // Submit the page
return true;
} else if
(document.form. category.option s[document.form.c ategory.selecte dIndex].value
== "option2"){
document.formSe arch.action = "whatever2.php" ;
document.formSe arch.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=documen t.formx3.action ='".$var1."'; document.formx3 .submit();

Should have been:

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

the quotes are escaped for PHP.
Jul 23 '05 #7
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
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 "malfunctio n" 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
"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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2411
by: Paul M | last post by:
Hi, I've got a recordset consisting of many records (anything up to 250) which currently loops to populate a form in each iteration. I need to post the form to an external URL on each loop, or alternatively populate multiple forms on one page and post each one in sequence. The problem I've had is that the posting seems to be too quick and only a handful arrive. I can loop with an alert pop-up that prompts for the next send, but
4
7794
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM: The form won't submit if the link is clicked, but will submit if the SUBMIT button is clicked. I need to call a function to change the form's action according to user's input before it is submitted.
29
8781
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0 CLASSID='CLSID:0AE533FE-B805-4FD6-8AE1-A619FBEE7A23' CODEBASE='IntraLaunch.CAB#version=5,0,0,3'>") Response.Write("<PARAM NAME='ImageLoc' VALUE='Null'>") Response.Write("<PARAM NAME='ImageSrc' VALUE='Null'>")
6
4044
by: Joop | last post by:
Hi all, I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-) So, here's my problem : I've created a table in my document, presenting a list of items, one can 'select' by clicking on it... (Kinda like a menu, you make your choice from) But since this table can get very long, I've put something of a 'search-form' on top, which enables the user to make a
5
8449
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform' action='ins_op.php' method='post'>"; lots of form stuff
4
5590
by: Dmitry Korolyov [MVP] | last post by:
When we use btnSubmit.Attributes = "javascript: this.disabled=true;" to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer postback. I.e. the button does go disabled, but the form does not invoke submit() method. Of course, it does work fine without this property. Clues?
8
5080
by: Gert | last post by:
Hi, I have a form (server side) because of the filling of variables through the application. But now I need to post it to an url on submit. My .HTML form looks like this, but how to translate it to asp.net vb code? !--<FORM ACTION="/test/test.php" METHOD=POST>--> <form action="https://multipay.net/transaction/mpmain.php" method="post"> ....
10
6091
by: ljlolel | last post by:
So.. I have a form that submits to an ASP.net site made in C-sharp. The ASP site is not mine, i do not have the server side code. When I submit from my form by pressing the Submit button, I get different results than when I use a javascript submit: form1.submit();. I think the javascript submit is working as it should, since I want the server to process an __EVENTTARGET posting. When I click the submit button, it does not process the...
5
7532
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some radio buttons (for each row of the table) and a main submit button. On clicking submit..i want to loop through the table..pick up the first <TDbeing the user ID and the value of the radio button clicked (currently I have my radio button ID set...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.