Submit form automatically

Discussion in 'PHP' started by makhan, Jun 16, 2007.

  1. #1
    Hi

    I am trying to submit the form automatically without button, but its not working. Following is the code


    <?php


    $name="Myname";


    <form name="MyForm" action="/cgi-bin/matweb.exe" method="POST">
    <input type="hidden" name="mlmfile" value="test">
    <input type="hidden" name="name" value=" <?PHP echo $name ?>" >
    <p><input type="submit" name="Submit" value="Execute"></p>

    </form>

    <script type="text/javascript" language="JavaScript"><!--

    document.MyForm.ThisPageURL.value = document.URL;

    var x = new Date();

    document.MyForm.TimeZoneOffset.value = x.getTimezoneOffset();

    document.MyForm.submit();

    //--></script>

    ?>
     
    makhan, Jun 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    I don't know why you're posting this in PHP, but try changing the name of the submit button to something else, as it's probably conflicting with JavaScript's submit() function.
     
    nico_swd, Jun 17, 2007 IP
  3. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #3
    This problem seems to be related to Javascript.
     
    coderbari, Jun 17, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    <?php
    
    
    $name="Myname";
    ?>
    
    <form name="MyForm" action="/cgi-bin/matweb.exe" method="POST">
    <input type="hidden" name="mlmfile" value="test" />
    <input type="hidden" name="ThisPageURL" value=""/>
    <input type="hidden" name="TimeZoneOffset" value=""/>
    <input type="hidden" name="name" value="<?PHP echo $name ?>" />
    <p><input type="submit" name="Submit" value="Execute" /></p>
    
    </form>
    
    <script type="text/javascript" language="JavaScript"><!--
    
    window.onload=function( )
    {
    	document.MyForm.ThisPageURL.value = document.URL;
    
    	var x = new Date();
    	
    	document.MyForm.TimeZoneOffset.value = x.getTimezoneOffset();
    	
    	document.MyForm.submit();
    }
    
    //--></script>
    
    HTML:
     
    krakjoe, Jun 17, 2007 IP
  5. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #5
    You seem to have placed the whole javascript section inside the php section. This won't work. You need to end the php section like krakjoe did. Then use the javascript somewhere in the page. If you use it in the header i.e between <head> and </head>, you need to use the onload attribute like krakjoe did. Otherwise, if you put it right above your </html> tag, it will work.
     
    NoamBarz, Jun 17, 2007 IP
  6. makhan

    makhan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks guys for your help. Actually what I am trying to do is test if I can pass a simple string to the program matweb.exe. Since I wanted to do it automatically I found this javascript code which automatically submits the form. I don't really want to pass the values of ThisPageUR and TimeZoneoffset.

    Ultimately I will have some values passed to this php script from flash movie and I want to pass this value passed to the program matweb.exe. Can someone please help me with that.
     
    makhan, Jun 17, 2007 IP