Hi

How do I create form data and auto-submit it using header() statements?

I need to create some data from a php script that will auto submit to another web-page.

Cookies aren't any use here as the destination site may be https or not the same as the source.

I don't want to just generate a form full of hidden fields that I want the target script to read and put a submit button on the screen because I need it to be relatively transparrent.

I've tried the hidden type and then javascript to call the submit function but in IE4 (this has to be backwards compat) the script:

<form method=post action="target.url" name="myform">
<input type=hidden name="field" value="value">
</form>
<script language=JavaScript>
document.myform.submit();
</script>

Gives me an error in IE4 but works fine in IE5 or NS4.x

Any suggestions?

James

    Try the <body onload=javascriptfunction> or <body onload=document.formname.submit()>

    and see if that can do it.

      or write a javascript function
      with form.submit & you can attach the function with certain event and that will force submit the form

        I ran into something like this yesterday. I think your problem has to do with spotty cross-browser support of things like document.name.method(); Try something like document.forms[0].submit(); instead, that's how I got it to work.

          Hi

          Thanks for your help.

          The solution was a little simpler than I thought.

          Basically, the <BODY> tag has to be present in your document, otherwise, older browsers can't interpret the JavaScript.

          So:

          <BODY>
          <FORM>
          ... form stuff
          </FORM>

          <SCRIPT LANGUAGE=JavaScript>
          document.forms[0].submit();
          </SCRIPT>
          </BODY>

          Works fine. If you omit the body tag and use the forms[0] bit you get an error like:

          No such object "document.forms.0.submit"

          Thanks once again for your help.

          James

            Write a Reply...