• I tried the code from the other post that is closed now and it works kind of. But the way it works is I have to have a first name field [sliced_client_fname] and last name field [sliced_client_lname] and filling those two out then combine together and fill out all three fields. However, that’s not what I want. I want to just fill out the full name field and then split it. I found a solution here on stackoverflow. However, I was wondering if someone could throw me a few pointers on how to implement it into the plugin code. Here’s the relevant code (regex):

    function split_name($name) {
        $parts = array();
    
        while ( strlen( trim($name)) > 0 ) {
            $name = trim($name);
            $string = preg_replace('#.*\s([\w-]*)$#', '$1', $name);
            $parts[] = $string;
            $name = trim( preg_replace('#'.$string.'#', '', $name ) );
        }
    
        if (empty($parts)) {
            return false;
        }
    
        $parts = array_reverse($parts);
        $name = array();
        $name['first_name'] = $parts[0];
        $name['middle_name'] = (isset($parts[2])) ? $parts[1] : '';
        $name['last_name'] = (isset($parts[2])) ? $parts[2] : ( isset($parts[1]) ? $parts[1] : '');
    
        return $name;
    }
Viewing 1 replies (of 1 total)
  • Thread Starter symbi0tic

    (@symbi0tic)

    I figured it out and it only took three lines of code rather than what I just posted. Plus some of the changes from the previous post from over a year ago. I’ll try to explain below. And this is from stackoverflow from the same page, I didn’t figure it out on my own.

    Follow the original guide here from over a year ago. Except make one change.

    Do not follow the first instruction to replace:
    $name = $posted_data['sliced_client_name'];
    in the QUOTE section.

    Instead add these four lines under the other variables

    $parts = explode(' ', $posted_data['sliced_client_name']);
    $fname = array_shift($parts);
    $lname = array_pop($parts);
    $mname = trim(implode(' ', $parts));

    Everything else do the same.

    • This reply was modified 4 years, 11 months ago by symbi0tic.
    • This reply was modified 4 years, 11 months ago by symbi0tic.
Viewing 1 replies (of 1 total)
  • The topic ‘Client Name not populating First Name and Last Name’ is closed to new replies.