I understand that soldiers are generally divided into different groups by wealth and age, but what I don't get is how the recruitment happened.
For example, during the Second Punic War, Rome lost army after army to Hannibal and had to recruit more troops. How did these people come into the Field of Mars? Did they just think "Oh, Rome is at danger, I must join the army!" or were there "I want you for the US army" style things or did they just pick up a register of Roman names and say these people are drafted?
It's a bit weird since the soldiers had to pay for their own equipment, so forcing people to join would be a bit... selfish? I don't know how to describe it.
The Greek historian Polybius, who wrote a history of Rome in the 130 BC timeframe, describes in detail how the "Dilectus" worked, the formal levy done to raise the Roman contingent of two consular armies (raising a total of four Roman legions, infantry and cavalry):
After electing the consuls, they appoint military tribunes, fourteen from those who have seen five years' service and ten from those who have seen ten. As for the rest, a cavalry soldier must serve for ten years in all and an infantry soldier for sixteen years before reaching the age of forty-six, with the exception of those whose census is under four hundred drachmae, all of whom are employed in naval service. In case of pressing danger twenty years' service is demanded from the infantry. No one is eligible for any political office before he has completed ten years' service. The consuls, when they are about to enrol soldiers, announce at a meeting of the popular assembly the day on which all Roman citizens of military age must present themselves, and this they do annually. On the appointed day, when those liable to service arrive in Rome, and assemble on the Capitol, the junior tribunes divide themselves into four groups, as the popular assembly or the consuls determine, since the main and original division of their forces is into four legions. The four tribunes first nominated are appointed to the first legion, the next three to the second, the following four to the third, and the last three to the fourth. Of senior tribunes the first two are appointed to the first legion, the next three to the second, the next two to the third, and the three last to the fourth. The division and appointment of the tribunes having thus been so made that each legion has the same number of officers, those of each legion take their seats apart, and they draw lots for the tribes, and summon them singly in the order of the lottery. From each tribe they first of all select four lads of more or less the same age and physique. When these are brought forward the officers of the first legion have first choice, those of the second choice, those of the third, and those of the fourth last. Another batch of four is now brought forward, and this time the officers of the second legion have first choice and so on, those of the first choosing last. A third batch having been brought forward the tribunes of the third legion choose first, and those of the second last. By thus continuing to give each legion first choice in turn, each gets men of the same standard. When they have chosen the number determined on — that is when the strength of each legion is brought up to four thousand two hundred, or in times of exceptional danger to five thousand — the old system was to choose the cavalry after the four thousand two hundred infantry, but they now choose them first, the censor selecting them according to their wealth; and three hundred are assigned to each legion.
That is the most detailed historic description of the levy relating to the mid Republican era. Based on Polybius' description, it seems that all Romans of the age of 17-46, regardless of where ever they lived, who still owed military service (16 for classes who served in the infantry, 10 years for those of the Equestrian Order) were to report for the Dilectus to the Capitol of Rome on a designated date, provided in advance by messengers.
Because at the time most Romans, especially property owners and those who were most suitable for military service (rural farmers) didn't live in Rome itself, this was obviously a problem, and likely was a prime reason recruitment became so difficult. Additionally, enforcement was problematic, as "draft avoidance" does seem to have been an issue in the 2nd Cent BC, as many Romans, while eager to fight battles of conquest that would gain them much in plunder, were not eager to serve in garrison legions in places like Spain especially, where constant raiding, banditry, and tribal rebellions meant nonstop service, lots of nasty fighting, with little to no hope of gathering any sort of plunder to make the effort seem worthwhile (many modern historians call the wars in Spain "Rome's Vietnam", though it lasted well over a century). Roman citizens who were eligible, who didn't show up, would need to provide justification if called on it by any magistrate, which was a possibility. If they didn't, they could be punished, to include fines or even loss of citizenship. However, it seems to have been rarely enforced, which might explain the issues of the late 2nd Cent BC when certain draconian measures and reforms were made to increase the pool of potential recruits.
The dilectus changed during the Late Republic, most point to during or after the Social War (when most of Italy was given the full Roman citizenship), at which point tribunes, legates, and commanders (the duties seemed split) would go to the individual Roman communities and recruit them locally to raise cohorts, then combine cohorts to form into legions. In this manner, some cohorts might be raised in Rome itself, others from municipia (established towns) and coloniae (colonies) all over the Roman controlled empire.