Re: Javascript and $_POST

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is nothing wrong with the way you want to submit this form.
Although it's JS :) The sample code you posted was broken in some ways...

missing document. in JS en missing input field to check.

This sample works fine ... 

test.html

<script language="JavaScript">
function checkForm() {

if (document.inputForm.cc_phone_number.value == "") {
    alert( "Please enter a phone number." );
    document.inputForm.cc_phone_number.focus();
    return;
}

document.inputForm.submit();
}

</script>
<title></title>
<LINK rel="stylesheet" type="text/css" href="../../CSS/background.css">
</head>
<body>
<div align="center"> 
<h2></h2>
<h3>Submit a New Payment.</h3>
</div>

<form name="inputForm" action="save.php" method="post" enctype="multipart/form-data">
<input type="text" name="cc_phone_number" value="8756765756757" />
<table align="center" border="0" cellpadding="0" cellspacing="0" width="680">
<tr>
    <td width="64" align="left"><a href="javascript:checkForm()" title="Save">Save</a></td>
    <td width="616" align="left"><a href="javascript:closeThis()" title="Close">Close</a></td>
</tr>
</table>
</form>

</body>
</html>

save.phhp

<?php print_r($_POST); ?>

Think some other code or JS errors might stop the form from sending data.



On Thu, 8 Feb 2007 09:09:34 -0500, "Dan Shirah" <mrsquash2@xxxxxxxxx> wrote:
> Nope, same result unfortunately.
> 
> On 2/8/07, Németh Zoltán <znemeth@xxxxxxxxxxxxxx> wrote:
>>
>> On cs, 2007-02-08 at 08:56 -0500, Dan Shirah wrote:
>> > Okay, I'll try your spacer solution.   Where do you think I should add
>> > it?
>>
>> I put it right before the </form> tag, but I think you could put it
>> anywhere between the <form> and the </form>
>>
>> greets
>> Zoltán Németh
>>
>> >
>> > On 2/8/07, Németh Zoltán <znemeth@xxxxxxxxxxxxxx> wrote:
>> >         On cs, 2007-02-08 at 08:41 -0500, Dan Shirah wrote:
>> >         > I should not need an actual Button if my link to checkForm()
>> >         ends with
>> >         > document.inputForm.submit(); which tells the form to submit,
>> >         right?
>> >
>> >         well, you should be right...
>> >         but I remember a year ago or so I had a similar problem and
>> >         the image
>> >         input solved it... but I'm not sure whether it was exactly the
>> >         same
>> >         problem or not, so it might be complete bullshit ;)
>> >
>> >         greets
>> >         Zoltán Németh
>> >
>> >         >
>> >         > On 2/8/07, Németh Zoltán <znemeth@xxxxxxxxxxxxxx> wrote:
>> >         >         On cs, 2007-02-08 at 08:14 -0500, Dan Shirah wrote:
>> >         >         > Okay, I edited my page per some suggestions
>> >         here.  Below is
>> >         >         what I now have:
>> >         >         >
>> >         >         >
>> >         >         > <script language="JavaScript">
>> >         >         > function checkForm() {
>> >         >         >
>> >         >         >  // ** START **
>> >         >         >   if (inputForm.cc_phone_number.value == "") {
>> >         >         >     alert( "Please enter a phone number." );
>> >         >         >     inputForm.cc_phone_number.focus();
>> >         >         >     return;
>> >         >         >   }
>> >         >         >
>> >         >         > ******Lots of other checks here, just left out for
>> >         >         length******
>> >         >         >
>> >         >         >    document.inputForm.submit();
>> >         >         > }
>> >         >         >
>> >         >         > </script>
>> >         >         > <title></title>
>> >         >         > <LINK rel="stylesheet" type="text/css"
>> >         >         href="../../CSS/background.css">
>> >         >         > </head>
>> >         >         > <body>
>> >         >         > <div align="center"> <h2></h2>
>> >         >         >    <h3>Submit a New Payment.</h3>
>> >         >         > </div>
>> >         >         > <form name="inputForm" action="save.php"
>> >         method="post"
>> >         >         > enctype="multipart/form-data">
>> >         >         >
>> >         >         > ******Lots of form data here******
>> >         >         >
>> >         >         > <table align="center" border="0" cellpadding="0"
>> >         >         cellspacing="0"
>> >         >         > width="680">
>> >         >         >  <tr>
>> >         >         >  <td width="64" align="left"><a
>> >         >         href="javascript:checkForm()"
>> >         >         > title="Save">Save</a></td>
>> >         >         >  <td width="616" align="left"><a
>> >         >         href="javascript:closeThis()"
>> >         >         > title="Close">Close</a></td>
>> >         >         >  </tr>
>> >         >         > </table>
>> >         >         > </form>
>> >         >         > </body>
>> >         >         > </html>
>> >         >         >
>> >         >         > Now when I submit my page it still perfroms all of
>> >         the
>> >         >         javascript checks
>> >         >         > correctly, but once it gets to the
>> >         >         document.inputForm.submit(); part it
>> >         >         > returns the following error.
>> >         >         >
>> >         >         > Error: Object doesn't support this property or
>> >         method.
>> >         >         > Code: 0
>> >         >         >
>> >         >
>> >         >         maybe because you don't have submit button in the
>> >         form?
>> >         >         try to include something like this
>> >         >         <input type="image" src="./images/spacer.gif">
>> >         >         where spacer.gif is an 1x1 blank image
>> >         >
>> >         >         I remember some similar situation where it helped,
>> >         but I'm not
>> >         >         sure
>> >         >
>> >         >         hope that helps
>> >         >         Zoltán Németh
>> >         >
>> >         >         >
>> >         >         >
>> >         >         > On 2/7/07, Paul Novitski
>> >         <paul@xxxxxxxxxxxxxxxxxxx> wrote:
>> >         >         > >
>> >         >         > > At 2/7/2007 01:34 PM, Dan Shirah wrote:
>> >         >         > > >I have a form that uses Javascript to validate
>> >         form field
>> >         >         entries, and if
>> >         >         > > >they are incorrect it returns an error to the
>> >         user.
>> >         >         > > >
>> >         >         > > >After the Javascript processing is complete, it
>> >         submits
>> >         >         the form to my
>> >         >         > > save
>> >         >         > > >page. However it seems that once the processing
>> >         is
>> >         >         complete and it passes
>> >         >         > > to
>> >         >         > > >the save page, none of my $_POST variables are
>> >         being
>> >         >         passed.
>> >         >         > >
>> >         >         > >
>> >         >         > > Of course, all of your form fields need to be
>> >         inside the
>> >         >         same
>> >         >         > > <form></form> tags as your submit button.  The
>> >         sample HTML
>> >         >         you posted
>> >         >         > > did not indicate that you'd done this.
>> >         >         > >
>> >         >         > > Regards,
>> >         >         > >
>> >         >         > > Paul
>> >         >         > > __________________________
>> >         >         > >
>> >         >         > > Paul Novitski
>> >         >         > > Juniper Webcraft Ltd.
>> >         >         > > http://juniperwebcraft.com
>> >         >         > >
>> >         >         > >
>> >         >
>> >         >
>> >
>> >
>>
>>
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux