[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

validate form > push to popup window > clear original form ??HELP??

I have a form in which I want to validate fields and if they all pass create a popup and pass the form values to the popup.

I also need to clear the contents of the form on the originating page after the fields have been validated and submited.

Here is the code I have going right now but it wont seem to work together.

<script type="text/javascript" src="ScriptIncludes/jvalx.js"></script>

<script>
function openWindow(frm) {
window.open ('about:blank', 'newWin', 'scrollbars=yes,status=yes,width=300,height=300');
frm.target="newWin";
frm.submit();
}
</script>

<form method="post" action="form_scripts/salescontact.php" onsubmit="return jValidate(this, true); openWindow(this.form);">
<some form fields>
</form>

I am using a validation library for the validation.

Also not included in the above code is a way to clear the contents of the originating form after it has passed validation and is sent to the popup.  I have no idea how that can be done.

Question ONE:  Do you even understand what the heck I am talking about?
Question TWO: Do I even understand what the heck I am talkin about?
Question THREE: Anyone have a solutions to help me here?

Thanks in advance!
0
lightrayz
Asked:
lightrayz
  • 7
  • 5
  • 4
1 Solution
 
devicCommented:
hi lightrayz,

yes, yes, yes!

it's easier as you think ;)

=====================
<script>
function jValidate(obj,state)
{
      /* test test test*/
      if(true)
      {
                  window.open ('about:blank', 'newWin', 'scrollbars=yes,status=yes,width=300,height=300');
                  obj.target="newWin";
                  return true;
      }
}
</script>
<form method="post"  action=http://sembel.net/tools/q.php onsubmit="return jValidate(this, true);">
      <input type=text name=q value=hurra>
      <input type=submit>
</form>
0
 
devicCommented:
ah about clear:

in popup add this code:
=======================
<script>
opener.document.forms[0].reset();
</script>
0
 
devicCommented:
if you can not change a source of the popup, then maybe use setTimeout:
=============================
<script>
function jValidate(obj,state)
{
      /* test test test*/
      if(true)
      {
                  var mywin = window.open ('about:blank', 'newWin', 'scrollbars=yes,status=yes,width=300,height=300');
                  setTimeout("document.forms[0].reset()",1000);
                  obj.target="newWin";
                  return true;
      }
}
</script>
<form method="post"  action=http://sembel.net/tools/q.php onsubmit="return jValidate(this, true);">
      <input type=text name=q value="">
      <input type=submit>
</form>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
lightrayzAuthor Commented:
hello Devic,

Its not calling my validation script correctly because the validation is not working anymore.

I put your script in the head of main doc including the setTimout function.

I also put the little reset script at the top of my php processing page (which gets served in the popup).

ONE: Its acting real wierd.  Sometime it will submit and give me the pop up at the correct dimensions and sometimes it gives me the pop up at full screen.

TWO: it's not validating through this script <script type="text/javascript" src="ScriptIncludes/jvalx2.js"></script>

Here is a snippet from the top of the validation script:

/*** MAIN VALIDATION FUNCTION ***/
function jValidate(f, bAllowMultipleSubmission) {
      //  ignore NS4.x
      if (document.layers) {
            return true;
      }
      else {
            //  loop through all form elements
            if (window.bSubmitted) return false;
            if (self.jvalOverridden) return true;

You could get the whole script hereif you are so inclined: http://www.busweekly.com/ScriptIncludes/jvalx2.js

And here is the page I am trying to use it on (Its the CONTACT FORM on the right): http://www.busweekly.com/freesubscription.shtml

I tried putting your script just above the ELSE statement of the validation script in different variations but could not get anything to work.

Do you have anymore ideas based on this info I provided?

Thank you for your help =)



0
 
devicCommented:
ONE:  there, where you inserted the function, that I posted, replace it with this:
====================================================
<script>
function ValidateAndSubmit(obj,state)
{
      if(jValidate(obj, state))
      {
            window.open ('about:blank', 'newWin', 'scrollbars=yes,status=yes,width=300,height=300');
            obj.target="newWin";
            return true;
      }
      else
      {
            return false;
      }
}
</script>






TWO: in the update_form replace onsubmit with:
==================
 onsubmit="return ValidateAndSubmit(this, true);"


THREE: delete or rename bad name "submit" in submit button


FOUR: have a nice day ;)
0
 
lightrayzAuthor Commented:
hey Devic,

It works except now it is not passing the form values into the popup window.  Also it is not clearing the form after submit.

It is however validating and then sending to the popup and the popup is always the correct size .. bravo!

Thanks for your continued help.
0
 
ThaSmartUnoCommented:
im assuming devic is asleep ... but points definitly to him/her since he/she had the code, but didnt put it together ...

in his step ONE add this:
after obj.target="newWin";
  setTimeout("document.forms[0].reset()",1000);
  obj.submit();
0
 
devicCommented:
lightrayz,
to be sure that is working use as action this link:http://sembel.net/tools/q.php
0
 
devicCommented:
as noticed ThaSmartUno I forgot some parts of code ;)

anyway here is a test page, where you can test it and can not say that this doesn't work ;)

http://home.arcor.de/athens/expexc/js/test/lightrayz/form.html
0
 
lightrayzAuthor Commented:
I see your test page and the form does indeed submit now but not in it's own pop-up.

I have tried the URL your provided in IE, Firefox and Opera and they all serve the results page in the same window.

I know you are asleep right now so I will fiddle with this today to see if I can get it to work as you say that it should =)

Thanks
0
 
ThaSmartUnoCommented:
it does submit in its own popup for more (IE 6)
0
 
lightrayzAuthor Commented:
I think I may have found the problem .. I am testing some more then will post again.
0
 
devicCommented:
btw I don't sleep, I am in Germany

and at home and in office I tested under IE6 and Firefox without any problem.

maybe I don't understand something
0
 
ThaSmartUnoCommented:
more = me (typo in my post)
0
 
lightrayzAuthor Commented:
Ok I got it working but here is what I had to do.

First:  The validation script highlights the incorrect fields but does not reset them when the form was resetting.  So I changed the reset to actually refresh the whole page.

Here is the code:

setTimeout("document.contact_form.reset(); window.location = 'freesubscription.shtml';",1000);

of course I put name="contact_form" in the start tag of the form so that it works with the reset command.

Second:  I put back in name="submit" in the form button. Earlier in this thread you said that I should remove it so I did.  

/// THREE: delete or rename bad name "submit" in submit button ///

The php script needs this apparently to process the from so when i added it back everything started working again.

I pulled your test script and put your document and my document side by side.  When I saw that difference I went and looked at the PHP script and sure enough it needed that value to process.

So now it is all working just great!!

THANK YOU Devic and ThaSmartUno you are great experts =)
0
 
ThaSmartUnoCommented:
please note that it was all devic not really me =)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now