jQuery plugin for binding form attributes to links
- Include jquery.formlink.js in your page
- Use the
data-formlink
attribute to bind links to input fields - Use the
data-formlink-replacements
if you would like to replace som part of the input field in links target url.
As an alternative to step 2 and 3, you can use the following javascript
$(target).formlink(replacements);
Target should be a jQuery selector for input elements and the optional replacements parameter should be an dictionary used to replace parts of the input name used when link is clicked.
The following code can be used if you want to auto-fill the username field in a password recovery form when user clicks "Forgotten your password?".
<input id="LoginForm_username" name="LoginForm[username]" />
<a href="passwordRecovery.php" data-formlink="#LoginForm_username" data-replacements='{"LoginForm": "PasswordRecoveryForm"}'>Forgotten your password?</a>
When link is clicked, the following url is opened passwordRecovery.php?PasswordRecoveryForm[username]=VALUE_FROM_USERNAME_FIELD
.