Skip to content Skip to sidebar Skip to footer

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

Solution 1:

        <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();       
}); 

Solution 2:

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']; ?>"/>

Solution 3:

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


Post a Comment for "Auto Populate Form And Auto Submit With URL Parameters"