Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Navigation
Latest Addons
Xbox Leaderboards 5
Cookiebar Panel 70
AD Gallery 151
SyntaxHighlighte... 63
Newsletters v4.03 168
Facebook Like Box 201
Newsletters v4.02 79
Metro 235
Facebook Connect 215
Shoutbox Panel 185
Redactor for PHP... 127
MI Floating Side... 132
Facebook Login/R... 180
Avatar Studio v2.03 215
Relationship Sta... 120
Popular Addons
iTheme2 5907
Arise 5869
User Control v1.23 4680
Event Calendar 4128
Photowidget panel 3921
Radio-Theme red2... 3394
Highslide Gallery 3359
CSS/JavaScript D... 3274
Facebook Connect... 3055
Dynamic Menu 2945
Slideshow Lightb... 2768
L-AMANT 2689
Enigma 2670
2Dark 2624
Black 2618
Articles Hierarchy
Articles Home » PHP-Fusion v7 Tutorials » jQuery & PF v7 - how to... part 1
jQuery & PF v7 - how to... part 1
As you know PF v7 includes jQuery framework. Currently there's no part of PF v7 where it is used. There was no time and good ideas how to use it. Below an example how to implement some jQuery code and don't modify PF v7 core.

1) easy way to validate INPUT, SELECT, TEXTAREA fields (based on edit_profile.php file):
- lets make new panel and paste code below, then save and enable new panel, go to edit profile and try password fields:


?>
<script type='text/javascript'>
$(function(){
$("input").blur(function(){
alert($(this).val());
});
});
</script>
<?php


On every field focus lost you should receive a message with current field entry. Nothing sepcial. But lets modify a code a little bit:


?>
<script type='text/javascript'>
$(function(){
$("input[@type=password]").blur(function(){
$("#"+$(this).attr("name")+"_validate").remove();
if ($(this).val().length>0 && ($(this).val().length<6 || $(this).val().length>20)) {
$(this).after("<div style='' id='"+$(this).attr("name")+"_validate'>Password should contain between 6 and 20 letters...</div>");
}
});
});
</script>
<?php


In this case our validation procedure checks password length of each input field of password type if there's any entry.

IMPORTANT! From jQuery v1.3.x selectors of attributes does not contain @ sign! So if you're already upgraded your jQuery remember to remove @ sign from above code.

In this way we can validate any of input, select or textarea fields. But we still need some code to stop post procedure for profile form. Below code hoe to avoid post procedure if any errors ocuurs in profile fields:


?>
<script type='text/javascript'>
var profile_errors = 0;
$(function(){
$("input[@type=password]").blur(function(){
profile_errors = 0;
$("#"+$(this).attr("name")+"_validate").remove();
if ($(this).val().length>0 && ($(this).val().length<6 || $(this).val().length>20)) {
$(this).after("<div style='background:yellow;border:1px solid red;color:red;padding:2px' id='"+$(this).attr("name")+"_validate'>Password should contain between 6 and 20 letters...</div>");
profile_errors++;
}
});
$("input[@name=update_profile]").bind("click", function(){
if (profile_errors>0) {
alert("Some of user fields contain errors\nPlease verify your data before update your profile.");
return false;
}
});
});
</script>
<?php


In above code we're checking password fields for any length errors. If they occurs wh're binding click fonction on submit button and displaying a message.

Of course this method is unobstructive for users with no JS enabled. In this case old submit and verify method of user profile will be used.
Posted by Wooya on October 17 2009 19:33:32
Comments
13606 #1 HobbyMan

on Oct 17 2009 at 22:31:12
Nice Smile
Can we have part 2 please?
3674 #2 Craig

on Oct 18 2009 at 14:05:32
Very good guide.Grin
1313 #3 Wooya

on Oct 23 2009 at 12:20:47
Sorry for formatting errors. This article must be reedited
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

Awesome! Awesome! 100% [3 Votes]
Very Good Very Good 0% [No Votes]
Good Good 0% [No Votes]
Average Average 0% [No Votes]
Poor Poor 0% [No Votes]
Official Home of PHP-Fusion uses cookies. Some may already have been set. Read more about our Cookies here.
Please click the button I Consent Cookies to hide this bar and accept our cookies. If you continue to use the site with no action taken, we'll assume that you consent our cookies anyway.
Cookiebar Panel byVenue
Shoutbox
You must login to post a message.

18-06-2013 19:37
yay. Thanks for the update

18-06-2013 19:00
Good day, the patch is out!

18-06-2013 15:50
hello friends, am new here. wana show me around? Grin

18-06-2013 15:08
G'day All, any progress reports for v.7.02.07? Wink

18-06-2013 07:39
morning

17-06-2013 13:13
Good evening. Smile

17-06-2013 08:17
Good morning!

17-06-2013 07:14
We do not have many V6 installations up and running today. There are some compatibility issues with V7 for sure.

17-06-2013 05:28
My question is to general public.

17-06-2013 04:58
Another question. How about v7 infusion used in v6 core phpfusion? Any problem?

Last Seens
Last Seen > Admins
[SA] Richard... 00:49:43
[A] NetriX 01:03:59
[SA] Domi 01:05:57
[A] Christian 01:41:49
[A] MarcusG 01:52:14


Last Seen > Members
[M] globefreak Online Online
[M] Archer 00:17:54
[M] svwkwk 00:22:22
[M] afoster 00:32:46
[M] wepo 00:43:13