Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:40:57+00:00 2026-06-13T01:40:57+00:00

I want to check if the client name exists then Not to create it.

  • 0

I want to check if the client name exists then Not to create it.

the functions and every thing is working perfectly.
What I need is: Function return true or false to my ajax function.

my create function in js and ajax is:

function createClient(){
       var newClientForm = $$('newClientForm').getValues();
       var client_name = newClientForm.client_name;

       if (client_name != ''){
       url_call = window.server_name + "/index.php/clients/create_new_client/"+client_name; 
       url_call = url_call.replace(/\n/g, '|');
       $.ajax({
              url: url_call ,               
              success: function(data) {
                       if ((data==true)||(data==false)){
                            alert('data true');
                        }


              }     
        }); 
        }else{            
            dhx.alert({title:'Error', message:"Please enter the client name."});
        }
    };

and my controller in cakephp

function create_new_client($string = null){
            $this->layout = 'default_really_empty';
            $string = urldecode($string);
            $explode_item = explode('^', $string);

            $client_name        = $explode_item[0]; 

            //--Sreach if the Client is already there don't create it
            $modelClassChild = 'Client';
            $this->loadModel($modelClassChild);                
            $objects=$this->$modelClassChild->find('all',array('conditions'=>array($modelClassChild .'.deleted'=>'0', 
                                                                                   $modelClassChild .'.name'=>$client_name)));
            foreach($objects as $object) { 
                $dbName = $object['Client']['name'];
            }                

            if ($client_name != $dbName){  
            //--Sreach if the Client is already there don't create it
                $clientArray = array();
                $fields = array();

                $clientArray['Client']['name']  = $client_name;
                $fields[] = 'name';

                $client_exists = FALSE;                    

                $this->Client->create();
                $this->Client->save($clientArray, true); 
           }else{
               $client_exists = TRUE;                   
           }
           $this->set('client_exists',$client_exists);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:40:59+00:00Added an answer on June 13, 2026 at 1:40 am

    Return the boolean value

    if ($client_name != $dbName){  
        //--Sreach if the Client is already there don't create it
        $clientArray = array();
        $fields = array();
    
        $clientArray['Client']['name']  = $client_name;
        $fields[] = 'name';
    
    
        $this->Client->create();
        $this->Client->save($clientArray, true); 
    
        return false;                    
    
    }else{
        return true;                   
    }
    

    Check the sucess callback of ajax as

    success: function(data) {
        if ((data==0)||(data==1)){
            alert('data true');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created this check: ' Check if windows or mac if not objFSO.FolderExists(\\Client\C$\.) then
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly
If i have this table on dataBase.js file: client.query( 'CREATE TEMPORARY TABLE IF NOT
I want to check on the client side that a file has been selected
A large number of clients want to check in with a server about once
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I want to check if my many column in datagridview is empty. here my
I want to check a particular file exist in Azure Blob Storage. Is it
I want to check whether any Zip file is present on a specified path.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.