As a background, see Philip and the Ethiopian Eunuch.
Acts 8:37 (NKJV) is an answer to the question from the man whether he could
be baptised: "Then Philip said: 'If you believe with all your heart, you may.'
And he answered and said: "I believe that Jesus Christ is the Son of God."
Philip has been explaining the gospel to an Ethiopian court official, and the official has responded enthusiastically, asking to be baptized immediately. In this verse,
Philip is giving a challenge and the official is responding. The format of the
challenge and response may even have been a practice in the early church:
a public confession used to verify that the person is saved, see Salvation.
But the text of this verse itself doesn't appear to be original.
The verse isn't found in the oldest and most reliable manuscripts of Acts.
Most modern translations include it in parentheses, or with a note stating as much.
The sentence doesn't express anything that contradicts the rest of Scripture,
but it was probably not part of Luke’s original writing.
This verse is added in NKJV, but excluded from several other Bible translations,
such as ESV and NIV.
Today, churches often have a more involved system. The new believer may attend a class to learn the details about Jesus, Christianity, and baptism. Usually, they are baptized only after they have demonstrated that they understand what it means.
See also the origins of various Bible translations explained at Background in
Bible Translations.
See also Critical verses in the Gospels at the end of The Four Gospels.