Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting Form to Popup window for processing

Status
Not open for further replies.

Slinka

Programmer
Aug 22, 2002
2
CN
Help me. I have been battling with this thing for ages. Have a subscribe to our mailing list thing on our site that I wish to submit to a popup window for processing but can't figure out how. If anyway can help you will be saving my life!

Here's the code as is:

Sign Up page - signup.asp
------------
<HTML>
<HEAD>
<script language=&quot;JavaScript&quot;>
var win = null;
function NewWindow(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+''
win = window.open(mypage,myname,settings)
}
</script>
</HEAD>
<BODY>
<form target=&quot;PopUp&quot; method=&quot;post&quot; onSubmit=&quot;NewWindow('subscribe.asp','PopUp','300','200','no','no')&quot;>
<span class=&quot;infobox&quot;>Email:</span>
<input name=&quot;u_email&quot; type=&quot;text&quot; value=&quot;<%= lcase(u_email) %>&quot; size=&quot;8&quot;>
<input type=&quot;submit&quot; value=&quot;Join&quot; name=&quot;u_submit&quot;>
</form>
</BODY>
</HTML>

When the page is submitted I want the following asp page to open in the popup window which then processes the form:

PROCESSING PAGE - subscribe.asp
---------------

<html>
<head>
<title>ITR Newsletter Subscription Request</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<link href=&quot;../itr.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<SCRIPT TYPE=&quot;text/javascript&quot;>
<!--
window.focus();
//-->
</SCRIPT>
</head>
<body>
<p>
<%
' Checks to see if the user inputted a value
' If so, remove leading and trailing blanks and upcase it
u_email= ucase(trim(request.form(&quot;u_email&quot;)))

' Grab the length of the email address inputted
email_len=len(u_email)

' if the user has inputted a value start checking it
if trim(u_email) <> &quot;&quot; then

' Loop that will check each character of the inputted value
' for the @ and the dot
for counter = 1 to email_len
'If there is an @ set u_at to the position it was found in
if mid(u_email,counter,1)=&quot;@&quot; then

' count the number of @'s
at_counter=at_counter+1

' if there is more than one add it to the message
if at_counter > 1 then
if (message = &quot;&quot;) then
message = &quot;<B>Errors Reported:</B><BR>&quot;
end if
message = message & &quot;There appear to be multiple @'s in the email address.<br>&quot;
end if

' if this is the 1st @ note the location in the string
if u_at = &quot;&quot; then
u_at=counter
end if ' end check for first @
end if ' end check for the @

'If there is an dot (.) set u_dot to the position it was found in
if mid(u_email,counter,1)=&quot;.&quot; then
if u_dot = &quot;&quot; then
u_dot=counter
end if 'end check for the first dot
end if 'end check for the dot

next

' Check to see if the dot comes after the @
' and that the first dot is not the last character
if (u_dot < u_at) or (len(u_email) <= u_dot+1) or ((u_dot-u_at) < 2) or (u_at < 2)then
if (message = &quot;&quot;) then
message = &quot;<B>Errors Reported:</B><BR>&quot;
end if
message = message & &quot;The email address convention appears to be wrong. <br>&quot;
end if 'end check for dot after the @

' Scan the user input to see that all inputted values are either a letter A-Z,
' a number 0-9 or if the character is a . or and @.
for counter=1 to len(u_email)
if (mid(u_email,counter,1) <> &quot;/&quot;) and ((mid(u_email,counter,1) > chr(45)) and (mid(u_email,counter,1) < chr(58))) or ((mid(u_email,counter,1) > chr(63)) and (mid(u_email,counter,1) < chr(91))) then
else

' Check it isn't the &quot;-&quot; character
if (mid(u_email,counter,1) <> &quot;-&quot;) then

' If it's an invalid charcter add it to the display message
if (message = &quot;&quot;) then
message = &quot;<B>Errors Reported:</B><BR>&quot;
end if
message = message & &quot;The following invalid character was found in the email address: &quot;&quot;&quot;& mid(u_email,counter,1)& &quot;&quot;&quot; <br>&quot;
end if 'end check for &quot;-&quot; character
end if 'end check for invalid characters
next 'end loop for invalid characters
end if 'end check for user input

' Check the email field for input if is blank
' then add to the display message
if (u_email = &quot;&quot;) then
if (message = &quot;&quot;) then
message = &quot;<B>Errors Reported:</B><BR>&quot;
end if
message= message & &quot;Please enter an email address.<br>&quot;
end if

'--------------------------------------------------------------------

' If the email address is not OK than display the error message(s)
if message <> &quot;&quot; or u_email = &quot;&quot; then
response.write &quot;<P class=&quot;&quot;StandardText&quot;&quot;>&quot;
response.write message
response.write &quot;</P>&quot;

'--------------------------------------------------------------------

' If all seems ok begin processing the email
else

'Lower case email
u_email = lcase(u_email)

' -----------------------------------------
' This is the begining of the email creation and execution

' Create a new mail object on the server
set sm = server.CreateObject(&quot;CDONTS.Newmail&quot;)

' Declare what address is sending the message
sm.from = u_email

' subject of the email
sm.Subject = &quot;&quot;

' Declare what address the message is being sent to
sm.to = &quot;mdaemon@it-r.net&quot;

' Write the users message to the body of the email
sm.body = &quot;SUBSCRIBE newsletter&quot;

' Specify format of email
sm.BodyFormat=0
sm.MailFormat=0

' Send the message
sm.Send

' Clean up the server object
set sm = nothing

' -----------------------------------------

'Reset all the variables

u_email = &quot;&quot;
message = &quot;&quot;

'You application has been sent!
response.write &quot;<P class=&quot;&quot;StandardText&quot;&quot;>&quot;
response.write &quot;Thankyou for signing up to the IT Resources newsletter.<BR><BR><B>Your subscription request has been sent!</B>&quot;
response.write &quot;</P>&quot;


end if %>
</p>
<p align=&quot;center&quot; class=&quot;infobox&quot;><a href=&quot;javascript: self.close()&quot;>close window</a></p>
</body>
</html>

This asp stuff works fine if i just link to this page but if I try to do it as a popup - nothing.

Thanks in advance
Slinka
 
Have you tried creating the window in response to clicking the submit button?

Code:
<form
action=&quot;subscribe.asp&quot;
Code:
method=&quot;post&quot;
target=&quot;PopUp&quot;
Code:
>
<span class=&quot;infobox&quot;>Email:</span> 
<input name=&quot;u_email&quot; type=&quot;text&quot; value=&quot;<%= lcase(u_email) %>&quot; size=&quot;8&quot;>
<input type=&quot;submit&quot; value=&quot;Join&quot; name=&quot;u_submit&quot;
onclick=&quot;NewWindow('subscribe.asp','PopUp','300','200','no','no')&quot;
Code:
>
</form>

 
Make that
Code:
onclick=&quot;NewWindow('','PopUp','300','200','no','no')&quot;

Clicking the submit button runs the NewWindow() function and creates the window named PopUp. The server processes the form data in the subscribe.asp script which also builds the page. The page is returned to the browser and loaded into PopUp because of target='PopUp' in the form tag.

The call to NewWindow() by onsubmit only looks for a value of true, then proceeds to submit the form. Normally this is a call to a validation script and must be made like so -

Code:
<form . . . onsubmit=&quot;return isTheFormDataValid()&quot; . . .>

 . . . 
<script>
function isTheFormDataValid(){
   //code to check the data entered in the fields.
   if ( badDataFound){
      return false;
   }else{
      return true;
   }
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top