Using UART to RS232 chips is the only option in this case? Are there
any alternative ways?
For converting from UART to RS-232, using RS-232 level-converter IC like MAX232 is the most economical, reliable and convenient approach. You can build the respective RS-232 line drivers and line receivers using discrete parts but that's not recommended for above mentioned reasons (economical, reliable and convenience).
I am planning to send UART data directly to the Uart to RS232
converter chip. I do not know how they work, codewise do I need to
change anything?
Coding wise nothing will change. Just verify taht the baud rate of your UART is supported by RS-232. Most MAX232 will operates up to 120 kbit/s and MAX3232 operates up to 250 kbit/s.
For typical connection where baud rate is generally 9600 either of IC will suffice.
Can I directly put UART tx data to the receive pin of these chips?
Your UART TX needs to connect to Logic Data Input pin of MAX232 (T1IN (Pin Number - 11) or T2IN (Pin Number - 10)).
Your UART RX needs to connect to Logic Data Output pin of MAX232 (R1OUT (Pin Number - 12) or R2OUT (Pin Number - 9)).
If you connect you UART TX to T1IN (Pin Number - 11) then you will get your RS-232 TX signal on T1OUT (Pin Number - 14) else if you connect you UART TX to T2IN (Pin Number - 10) then you will get your RS-232 TX signal on T2OUT (Pin Number - 7).
Similarly,
If you connect you UART RX to R1OUT (Pin Number - 12) then you have incoming RS-232 data/signal line should be connected to R1IN (Pin Number - 13) RS232 line data input(from remote RS232 system) or if you connect you UART RX to R2OUT (Pin Number - 9) then you have incoming RS-232 data/signal line should be connected to R2IN (Pin Number - 8) RS232 line data input(from remote RS232 system).