View Single Post
  #6  
Old 02-04-2014, 05:33 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,604
IntoRain is on a distinguished road
Default

Quote:
Originally Posted by Kyttias View Post
text
I didn't use $.ajax because $.post did the same in one line (I believe it's ajax too?), first is the url of the file, second is the data and third is the function that works the results. At least that's what I understood xD

Aah thanks for sharing! I will try to use all the .focus and .change functions to see if it corrects the spazzing that happens sometimes

There's a few issues with mysidia's pages, so I kinda went around the problems lol For example the php spits out errors in the result of the ajax request if the document isn't created and doesn't have a title, so you have to create it as a page. Because my function turns into a page itself, that means users can access it, so I made it throw exceptions if the the value recieved is null.

Then if the function is fine, the result spits out the full page's html xD I went around this by accessing the characters of the result (since it ends up being a string). So if the php echos 0 as result, the result will be a string with 0 followed by the predefined html of the page. So result[0] is the first element of that string and the result I actually want (that's why I compare result[0] and not result)

It's a very... sloppy way of going around it. And maybe it's what causes the spazzing by making it slow down, no idea xD I will try again with other ways soon enough x.x Anyway, I added this function to register.php page: (hopefully it's useful)

PHP Code:
public function checkusername(){
    
$mysidia Registry::get("mysidia");

    if(
$mysidia->input->post("username") == NULL)//works as $_POST[]
    
{
        throw new 
NoPermissionException("You specified an invalid action that cannot be completed.");
    }
        
$document $mysidia->frame->getDocument();    
        
$document->setTitle("error");
        
$username $mysidia->input->post('username');
        
$count $mysidia->db->select("users",array("uid"),"username = '{$username}' LIMIT 1")->rowCount();//database query
        
echo $count;//result
    

The javascript part is in registerview.php and is like what I wrote before ^^ (this is because apparently I need to put the php function inside a controller (register.php is the controller for the register page) if I want to use the url like 'page/function ' instead of 'page.php'. I tried creating a new blank page and use it like page.php but it gave out many errors)

Quote:
Originally Posted by Hall of Famer View Post
Well seems that a lot of you are struggling with javascript in Mysidia, particulally AJAX. I will try to make the GUI system better at handling javascript in Mys v1.4.0 so you can add javascript events like onclick, onkeypress easily. Not sure how much this will help though, but at least its some kind of improvements I can offer.
That would be pretty cool! Thank you! These verifications I don't really need to do them with javascript, but it makes the website look so much cleaner and gives us room for so many effects xD

----

OOOH I was checking the focus thing after a key press, I think that's why it spazzed! The code is now (I made it a function since I will use it for email as well):

PHP Code:
<script>

/**
*Recieves a string as input and depending on the type, makes the necessary
*verifications
*/
function checkinput(inputtype){
        
                switch(
type){
                    case 
1://for username
                        
if(input.length 20)
                        {
                            $(
'.div07').html('<i>Username has too many characters:</i>' input);
                                                         return;
                        }
//regex missing

                        
$.post('/register/checkusername', {username:input},function(result) {
                            if(
result[0] != '0'){
                                $(
'.div07').html('<i>Username is empty or is already being used:</i>' input)
                            }
                            else
                            {
                                $(
'.div07').html('<i>Username can be used:</i>' input)
                            }
                        });
                        return 
0;                        
                        break;
                    case 
2://for email
                        
                        
break;
                    default:
                        break;
                    }
            }
                                
            $(
document).ready(function(){
                var 
ready 0;                
                $(
'input#username').keydown(function(e){
                $(
'.div07').html('<i>Loading...</i>');    
                });
                
//var key = e.which;
                
var username = $(this).val();
                    $(
'input#username').focusin(function(){
                    
username = $(this).val();
                    });
                    $(
'input#username').focusout(function(){
                        
username = $(this).val();
                        
checkinput(username,1);    
                    });
                
                })
            
</script> 
I believe it is working properly now: http://stareach.x10.mx/register (this is my test site for 1.3.4 so no registration actually exists xD - but you can test the username input thing). It checks the name whe nthe box loses focus (when you click somewhere else), you can use TestAccount to check the already exists error
__________________


asp.net stole my soul.

Last edited by IntoRain; 02-04-2014 at 06:25 PM.
Reply With Quote