The Idea is to make simple dummy form as a macro with the use of ajax. Here my first try. The Request was sent but I ll get back the whole page. Where is the mistake?
def execute(macro, request):
template = '''
<script type="text/javascript">
$(document).ready(function() {
$("#login_form").submit(function() {
var unameval = $("#username").val();
var pwordval = $("#password").val();
$.post("intern", { username: unameval,
password: pwordval }, function(data) {
$("#status p").html(data);
});
return false;
});
});
</script>
<form id="login_form" method="post">
<p>Username: <input type="text" id="username" /></p>
<p>Password: <input type="password" id="password" /></p>
<p><input type="submit" value="Login" name="create"/></p>
</form>
<div id="status">
<p></p>
</div>
'''
request = macro.request
form = request.form
submitted = form.has_key('create')
if submitted: # user pressed button
return validate()
else:
return template
def validate():
form = request.form
username = form['username']
password = form['password']
if (username == "test" and password == "password"):
return "<strong>Login succeeded!</strong>"
else:
return "<strong>Login failed! Please try again.</strong>"