Middle Name in Name field creating error message

Hello everyone!!! So here is my problem…

When a user is making a donation in the Billing Information Name field and they enter a “middle initial” an error message of "Bill To Last Name is required. " appears and the transaction is declined. In the paypal.php file I have tried to edit the code so a middle initial is added to the first name but have been unsuccessful. What changes to the code do i need to make so a user can add a middle name or initial and the transaction will process. Here is the code currently that will only allow a First and Last name to be entered into the Name field.
Code in paypal.php file:

// donor info
$fullname = isset($_POST['gdlr-name']) ? strip_tags(trim($_POST['gdlr-name'])) : '';
$firstname = $fullname;
$lastname ='';
$name = preg_split('/\s+/', $fullname);
if(count($name) == 2)
$firstname = $name[0];
$lastname = $name[1];

Thanks in advance!!!

Why not just ask for their first and last names separately like just about every other checkout form does.

Yes, I think a much better approach would be to rethink the form inputs. eg.

dropdown - Mr / Mrs / Ms.
text - first name
text - optional middle initial - 1 character limit
text - last name
dropdown - Jr / Sr / III

That would also allow it to correctly handle last names that contain one or two spaces.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.