/    Sign up×
Community /Pin to ProfileBookmark

complex form submission need help thanks

I am struggling with this what i want to do is submit the form in a center pop up window. The submit button is a hyperlink not a submit button.

here is my code below thanks

<script type=text/javascript>
<!–
var win= null;
function NewWindow(myform,mypage,myname,w,h,scroll){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var settings =’height=’+h+’,’;
settings +=’width=’+w+’,’;
settings +=’top=’+wint+’,’;
settings +=’left=’+winl+’,’;
settings +=’scrollbars=’+scroll+’,’;
settings +=’resizable=yes’;
win=window.open(”,myname,settings);
myform.target=myname;

if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
function MM_openBrWindow(theURL,winName,features) {
window.open(”,winName,features);
}
//–>
</script>

<form name=”myform” action=”submit-form.php” onSubmit=”return NewWindow(myform,”,’EmailInfo’,’700′,’500′,scroll)”>

Search: <input type=’text’ name=’query’>

<A href=”javascript:document.myform.submit()” >Submit</A>

</form>

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJan 09.2007 — Add action="_blank" to your FORM tag.
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — if you do this it will not work. The form will just go to a blank page. and not Utilize the JavaScript popup window.

Any advise or help I much appreciate it.

<form name="myform" action="_blank" onSubmit="return NewWindow(myform,'submit-form.php','EmailInfo','700','500',scroll)">

Search: <input type='text' name='query'>

<A href="javascript:document.myform.submit()" >Submit</A>

</form>
Copy linkTweet thisAlerts:
@SaveSheepJan 09.2007 — i'm almost a noob as well, but does this work?

[code=html]<a href="#" onclick="win=window.open('','myWin','toolbars=0'); this.form.target='myWin';this.form.action='http://google.com/search'">[/code]
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — Here is the form code below. The problem is if you click on submit it goes to a blank pop up page. Not the php page I have stated. When you click on submit it will pop-up that window but the php will process the form variables. The form variable in this case would be "query".

Thanks for the help. I am just going nutz with this one.

<form name="myform" id='myform' action="_blank">

Search:

<input type='text' name='query'>

<!-- <A href="javascript:document.myform.submit()" >Submit</A> -->

<a href="#" onclick="return NewWindow('myform','submit-form.php','EmailInfo','700','500',scroll); document.myform.form.target='EmailInfo';this.form.action='submit-form.php'">submit2</a>

</form>
Copy linkTweet thisAlerts:
@SaveSheepJan 09.2007 — here you go, this works for me

[code=html]
<form name="myform" id='myform' action="submit-form.php">
Search:
<input type='text' name='query'>
<a href="#" onclick="win=window.open('submit-form.php',null,'height=700,width=500,status=yes,toolbar=no,menubar=no,location=no'); this.form.target='myWin';this.form.action='http://google.com/search'">Submit Me</a>
</form>
[/code]
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — It works but if you are going to use php to process the form data it doesn't keep in mind i need the data from query string and I don't want concatenate the value like this submit-form.php=querystring=+document.form.query.value

Thanks for all your help let me know on a solution.

<form name="myform" id='myform' action="submit-form.php">

Search:

<input type='text' name='query'>

<a href="#" onclick="win=window.open('submit-form.php',null,'height=700,width=500,status=yes,toolbar=no,menubar=no,location=no'); this.form.target='myWin';this.form.action='submit-form.php'">Submit Me</a>

</form>
Copy linkTweet thisAlerts:
@mjdamatoJan 09.2007 — One option I can think of would be to append all the form variables into the querystring for the popup page. That page would then reference the form variables via $_GET rather than $_POST.
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — Not very effective. Its better to have the varibled within the form rather then the url.
Copy linkTweet thisAlerts:
@mjdamatoJan 09.2007 — Why is it not effective? If it works it is effective. Wether it is better or not to have the variables as POST objects instead of GET objects depends on several factors.

If I am understanding you correctly you want to submit the form on Page A, and have the form POSTed to a popup page (Page ?, but not have Page A refresh. Well, if that's correct you will have to do it in some backhanded way since forms will not do that.

In additional to the solution I offered above you could also try one of the following:

Have the form page submit to itself. When the page reloads and sees that it is receiving data it can save the from data and save to session variables and write a JS line to call a popup page that can acess the form variables through the session object.

Use AJAX to send the form data to a PHP processing page. That page can save the form data in the session or in a database. Then call the popup which can retrieve the data from the saved source.

On the popup page, simple refrence the field values from the parent page using opener.[i]formname.fieldname[/i].value
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — So basically I have a form click on the hyper link goes to a pop up and using php i get the form values. That is all what i want to do if i can do it with AJAX let me know and do i need to install anything on the server to handle AJAX.

Thanks...

<script type=text/javascript>

<!--

var win= null;

function NewWindow(myform,mypage,myname,w,h,scroll){

var winl = (screen.width-w)/2;

var wint = (screen.height-h)/2;

var settings ='height='+h+',';

settings +='width='+w+',';

settings +='top='+wint+',';

settings +='left='+winl+',';

settings +='scrollbars='+scroll+',';

settings +='resizable=yes';

win=window.open('',myname,settings);

myform.target=myname;

if(parseInt(navigator.appVersion) >= 4){win.window.focus();}

}

function MM_openBrWindow(theURL,winName,features) {

window.open('',winName,features);

}

//--></script>

<a href='#' onClick="document.email.submit();">Submit form</a>

<form name="email" method="post" action="http://www.myweb.com/displaydata.php" onSubmit="NewWindow(this,'','email','800','600','yes');" target="_top">

<input name='title' type='hidden' id='title' value="$out{title}" />

<input name='desc' type='hidden' id='desc' value='$out{description}'/>

<input name='link' type='hidden' id='link' value="$out{real_url}" />

</form>
Copy linkTweet thisAlerts:
@ricpJan 09.2007 — Two things here..

1) the onsubmit on the <form> tag will not trigger if you call the .submit() method via script

2) if you wish to send a form to a popup window, simply set open the new window with the name of the target used on the <form> tag. Like so..

<i>
</i>&lt;form target="myNewWindow" onsubmit="window.open('','myNewWindow','width=400,height=400')" action="foo.php" method="post"&gt;
:
// form content
:
&lt;input type="submit" value="submit"/&gt;
:
&lt;/form&gt;

Try that and you'll see how it works, just remember to give the url of the window as an empty string (or 'about:blank') and match the window name used for the popup to the target you set on the <form>.

Obviously you are using the .submit() method via script rather than a button (personally I think this is bad markup as mentioned below), so for your case you will need to call the window.open from the <a> link, before you call the .submit() method. Something like..

<i>
</i>&lt;form target="myNewWindow" id="myForm" action="foo.php" method="post"&gt;
:
// form content
:
&lt;/form&gt;
&lt;a href="#" onclick="window.open('','myNewWindow','width=400,height=400');document.getElementById('myForm').submit()"&gt;submit&lt;/a&gt;


As I say, this is bad code for several reasons; the use of an <a> to to submit the form in the first place, and then using an <a> with an onclick. Both of these are semantically bad and inaccessible. If I could suggest anything it would be to use the first code as that will submit the form to a normal new window without script (through the target attribute) or in a styled popup if script is available.

Hope that helps.
Copy linkTweet thisAlerts:
@realtime158authorJan 09.2007 — Thanks that is exactly what i wanted.
Copy linkTweet thisAlerts:
@toicontienJan 09.2007 — Sorry about that. I just realized my action="_blank" should have been target="_blank" ?
×

Success!

Help @realtime158 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...