A flame-retardant conductive cotton fabric switch was successfully prepared by the in situ polymerization of polyaniline doped with novel phytic acid (PA) by impregnation in an ice water bath for 24 h. The surface morphology, chemical composition, and thermal properties of the fabric before and after the in situ polymerization of polyaniline with PA were characterized by Fourier transform infrared spectroscopy (FTIR), X-ray photoelectron spectroscopy (XPS), scanning electron microscopy (SEM), thermogravimetric analysis (TG), and TG-FTIR. The experimental results demonstrated that the limiting oxygen index (LOI) of the original fabric increased to 32% and the sheet resistance (R-s) decreased to 1.13 k Omega square(-1). Under the PA de-doped state, the fabric had no flame-retardant and conductivity properties. Nevertheless, the excellent flame-retardant and conductivity properties of the fabric were obtained once more after re-doping with PA, which indicated that the flame-retardant and conductive textile switch was prepared successfully. Remarkably, the variation in the P content by XPS and the characteristic absorption peak of PA by FTIR made the doping behavior of PA on the surface of different fabrics clear. During the pyrolysis of the original and finished fabric, the maximum decomposition temperature (T-max) and the maximum emission (T-e) of light gas decreased from 380 degrees C to 290 degrees C, and the carbon residue content increased from 12.6% to 39.2% at 700 degrees C, which indicated that the in situ polymerization of aniline doped with PA resulted in the superior flame-retardant property of the fabric. This work provides a green method and basis for the preparation of multi-functional textiles, thus improving the added value of textiles.