Home  |  Linux  | Mysql  | PHP  | XML
From:Scott Date:Fri Jun 26 20:58:53 2009
Subject: HTML::Template, CGI::APP with the JSON + Jquery please help.
I cant seem to get this to work. I am trying to emulate this script
http://www.shawngo.com/gafyd/index.html , checks the username with a
database to see if its available.

I have tried the JSON + Jquery but i cant seem to get it to send the
current value of the text field.

Here is what my HTML Template looks like.

My Header includes:

<script src="/java/jquery-1.3.2.js"></script>

---

The main template:

<form method="post" action="index.pl"
enctype="application/x-www-form-urlencoded" name="reg">
<input type='hidden' name='rm' value='registrationemail' />
<font color="red">Username: </font></font><input type="textfield"
class="registrationfields" size="10" id="user" name="r_username"
onkeyup="exported_func( ['user'], ['test']);">
<TMPL_VAR NAME="TEST">
<span id="ajax_spinner" style="display: none;">
<img src="../images/spinner.gif"/></span>
<div id="display_user_details">
</div>
<div id="test">
</div>
<br/>
<font color="red">Password: </font><input type="password"
class="registrationfields" size="10" name="r_password"/>
<font color="red">Password-Check: </font><input type="password"
class="registrationfields" size="10" name="r_passwordcheck"/>
<br/>
First Name: <input type="textfield" class="registrationfields"
size="10" name="r_name"/><br/>
Last Name: <input type="textfield" class="registrationfields"
size="10" name="r_lastname"/><br/><br/>

Email Validation Required within 24 Hours of Account Creation.<br/>
<font color="red">Email: </font><input type="textfield"
class="registrationfields" size="10" name="r_email"/>
<font color="red">Email Check: </font><input type="textfield"
class="registrationfields" size="10" name="r_emailcheck"/>
<br/><br/>

Country: <input type="textfield" class="registrationfields"
size="10" name="r_country"/><br/>
City: <input type="textfield" class="registrationfields" size="10"
name="r_city"/><br/>
<br/>
How did you find us?
<br/>
<textarea rows=5 cols=20 class="registrationfields"
name="r_find"></textarea><br/>
<br/>
<br/>
<TMPL_VAR NAME="CAPTCHA">
<br/>
<input type="submit" value="Register"/>
</form>

<script>

// show the spinner for AJAX requests
$("#ajax_spinner").ajaxStart(function(){
$(this).show();
});
$("#ajax_spinner").ajaxStop(function(){
$(this).hide();
});

$("#user").keyup(function(){

$("div#display_user_details").html('');

$.getJSON('?ajax=1', function(result){
$("div#display_user_details").html(
result.username

);
});
});

</script>


Here is my CGI STUFF

sub usernameCheck
{
my ($query, $self) = @_;
#my $enteredusername = $query->param('r_username');
# check if its an AJAX submit
if ( $query->param('ajax') ) {
my $usernamecheck = check_usernames($enteredusername);
my $json = to_json($usernamecheck);
print "Content-type: text/html\n\n";
$self->header_add(-type => 'application/json');
print $json;
exit;
}
}


sub check_usernames
{
my ($t) = @_;
# pretend like we're doing some heavy task!
#my $answer = checkdbforusername($t);
sleep 0;
my $userresult = {
username => $t,
};
my $userresult2 = {
username => $t,
};
if($answer == 1)
{
return $userresult;
}
else
{
return $userresult2;
}
}

there is also a sub routine for checking the database, but right now i
am just trying to get it to print the value.

I have also tried cgi::ajax, but i cant get it to work with cgi::app and
html::template, this is a little over my head. Any help is appreciated.

Navigate in group perl.beginners at sever nntp.perl.org
Previous Next


Your recent visits
Re: script for shutdown remote machine
Re: help on example from "mastering algorithm with perl" on binarysearch
Re: floating point precision
Re: script to connect windows box from linux
Re: script for shutdown remote machine



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants