简体   繁体   中英

Auto populate form and auto submit with URL Parameters

I want to auto populate the below form with URL parameters for example using a URL like this:

example.co.uk/example.php?acct=wirelesslogicde&pwd=jenkins

I would also like it to Auto submit if possible, how would I go about this??

            <form action="http://www.twg.com/logincheck.aspx" method="post" name="login" style="margin-bottom: 0;">
            <p class="readmore" style="margin-bottom: 0;">
            <input name="module" id="module" type="hidden" value="HL"/>
            <input name="page" id="page" type="hidden" value="account.aspx"/>
            <strong>Account:</strong> <br />
            <input name="acct" id="acct" class="contact input" size="12" maxlength="16"/>
            <br />             
            <strong>Password:</strong> <br />
            <input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16"/><br /><br />
            <input type="submit" name="submit" id="submit" class="button" value="Login"/>
            </p>
            </form>

NEW FORM:

    <head>
    <script src="jq.js" type="text/javascript"></script>
    </head>

    <form action="http://www.zstats.com/logincheck.aspx" method="post" name="login" style="margin-bottom: 0;" id="zstatslogin">
    <p class="readmore" style="margin-bottom: 0;">
    <input name="module" id="module" type="hidden" value="HL"/>
    <input name="page" id="page" type="hidden" value="account.aspx"/>
    <strong>Account:</strong> <br />
    <input name="acct" id="acct" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['acct']; ?>"/>
    <br />             
    <strong>Password:</strong> <br />
    <input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['pwd']; ?>"/><br /><br />
    <input type="submit" name="submit" id="login" class="button" value="Login"/>
    </p>
    </form>

    <script type="text/javascript">
    $(document).ready(function() {
    $("#login").submit();       
    }); 
    </script>
        <form action="http://www.twg.com/logincheck.aspx" method="post" id="login" name="login" style="margin-bottom: 0;">
           <p class="readmore" style="margin-bottom: 0;">
              <input name="module" id="module" type="hidden" value="HL"/>
              <input name="page" id="page" type="hidden" value="account.aspx"/>
              <strong>Account:</strong> <br />
              <input name="acct" id="acct" class="contact input"  value="<?=$_GET['acct']?>" size="12" maxlength="16"/>
              <br />             
              <strong>Password:</strong> <br />
              <input type="password" name="pwd" id="pwd" class="contact input"  value="<?=$_GET['pwd']?>" size="12" maxlength="16"/><br /><br />
              <input type="submit" name="submit" id="submit" class="button" value="Login"/>
           </p>
        </form>

Use $_GET to get the values from URL .

For auto submit use, Make sure you have jquery plugin loaded before you use the following script. If you don't have JQuery added get it from JQuery and include the file like any other javascript file in your <head> section of HTML document.

$(document).ready(function() {
   $("#login").submit();       
}); 

you could do the autosubmit by using jQuery

$('#some_form_id').onLoad(function(){
$.Post('form_target',{parameters:values});
});

and for the populate you can add

<input name="acct" id="acct" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['acc']; ?>"/>
<input type="password" name="pwd" id="pwd" class="contact input" size="12" maxlength="16" value="<?php echo $_REQUEST['pwd']; ?>"/>

You can do this either by php using for example:

<input name="acct" id="acct" class="contact input" size="12" type="text" value=="<?php echo $_GET['acct'];?>" maxlength="16"/>

or using javascript, which would be a bit more complex, look at the window.location.search to filter down querystrings..

ref: https://developer.mozilla.org/en-US/docs/DOM/window.location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM