Closed Thread
Thread Tools Search this Thread
Unread 13th Apr 2010, 08:40 AM   #1
Dan Neece
War Room Member
 
danmart's Avatar
 
Join Date: 2008
Location: Phoenix,Arizona, USA.
Posts: 73
Thanks: 8
Thanked 8 Times in 8 Posts
Default
Javascript/Php Issue
Share on: 
fb share twitter share gplus share more share

I am working on a project where I want to take any opt in form and count how many times it was submitted. After extensive research (I know that Javascript is client side and PHP is server side) I came up with a solution.

What I did was to add a tag to the beginning of the form with an "onsubmit" tag calling a Javascript which in turn submits a hidden form which posts to my PHP program that updates the databases.

This works great except... If I leave the opt in page and come back, it won't work anymore. I have tried everything that I can think of, I changed the hidden form action to post the vars directly without using the hidden inputs, I have tried changing it to open the file in a hidden div or even the main window (The php program has no output) Does anyone have any ideas why it will stop working when the window looses focus? the code is added below:

<form onsubmit="return OnButton1();" action="http://yahoo.com">
<input type="text" value="Your Name Here" />
<input type="text" value="Your Email Here" />

<input type="submit" value=" " />
</form>
</div>

<form name = "Formzilla" action = "http://www.mysite.com/lpage/maillist.php" method ="post">
<input type="hidden" name = "item" value = "1">
<input type = "hidden" name = "page" value = "3">
</form>
<script language="javascript">
function OnButton1()
{
document.Formzilla.submit();
return true;
}
</script>
danmart is offline  
Unread 13th Apr 2010, 08:48 AM   #2
Dan Neece
War Room Member
 
danmart's Avatar
 
Join Date: 2008
Location: Phoenix,Arizona, USA.
Posts: 73
Thanks: 8
Thanked 8 Times in 8 Posts
Default
Re: Javascript/Php Issue
Share on: 
fb share twitter share gplus share more share

Sorry... The script will not post the hidden form. I have an implicit database call that would make an entry every time the program was called and I get nothing so I know that the form is not getting submitted.

oh and I get no errors and the main form works just fine.

An Update... I have found that If I refresh the page after leaving it and before I submit the form it will post the hidden form but not if I don't refresh the page.
danmart is offline  
Unread 13th Apr 2010, 09:11 AM   #3
Dan Neece
War Room Member
 
danmart's Avatar
 
Join Date: 2008
Location: Phoenix,Arizona, USA.
Posts: 73
Thanks: 8
Thanked 8 Times in 8 Posts
Default
Re: Javascript/Php Issue
Share on: 
fb share twitter share gplus share more share

Originally Posted by BenB969 View Post

I can't see why it doesn't work from the info you've given.

However I can suggest another method.

How about having just 1 form.
The form will be sent to the php file in your server.
The php file will add the data to your database.
It will then send the user to the original form destination.

This is a better way because it doesn't rely on the user browser.
That would work in most situations but not this. This is part of a system where you can add ANY autoresponder code and the program adds the tracking code automatically. I have no way of knowing the autoresponder vars so I can pass them to the PHP handler.
danmart is offline  
Closed Thread


Bookmarks

Tags
issue, javascript or php

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 08:39 AM.