SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Cha, Cha, Cha!!! Gamermk's Avatar
    Join Date
    Aug 2005
    Posts
    604
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alert() not working with Quickform

    I'm trying to call the Alert function within custom validation in Quickform.

    Code:
    $form->registerRule('city_rule','function','compareCities');  
    $form->addRule('city', 'Select a city OR enter a new one',
    'city_rule', $form->getElementValue('new_city'));
    		
    function compareCities($city_name, $city_value, $new_city)
    {
    	// if a city_value is not selected then a new city 
    	// must be entered	
    	if ($city_value == "0" && $new_city == "")
    	{
    		window.alert("This message is not working");
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }
    As indicated in the code the window.alert("This message is not working") isn't working.

    Any suggestions?
    People don't read ads. They read what interests them,
    and sometimes that happens to be an ad.
    TrulyBored.com | TankingTips.com

  2. #2
    Cha, Cha, Cha!!! Gamermk's Avatar
    Join Date
    Aug 2005
    Posts
    604
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya so it turns out that calling javascript within PHP doesn't exactly work...

    (slow day...)
    People don't read ads. They read what interests them,
    and sometimes that happens to be an ad.
    TrulyBored.com | TankingTips.com

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    js in PHP

    If you really want the alert maybe you could output the script tags too.
    PHP Code:
        if ($city_value == "0" && $new_city == "")
        {
            echo 
    "<script type='text/javascript'>";
            echo 
    'window.alert("This message is not working");';
            echo 
    "</script>";
            return 
    false;
        } 
    I guess it depends on if this script is "in" the page or running in the background.
    Also, it looks like the $city_name parameter is not being used?

  4. #4
    Cha, Cha, Cha!!! Gamermk's Avatar
    Join Date
    Aug 2005
    Posts
    604
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are correct $city_name isn't used simply because to my knowledge its required with custom validation for quickforms.

    The code you have given is what my next step was, but soon after I realized that without being able to do client side custom validation in quickform (its coming in quickform2 supposedly), it was no longer worth using quickform for the validation.
    People don't read ads. They read what interests them,
    and sometimes that happens to be an ad.
    TrulyBored.com | TankingTips.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •