Upstream of shocks, the foreshock is filled with hot ions. When these ions are concentrated and thermalized around a discontinuity, a diamagnetic cavity bounded by compressional boundaries, referred to as a foreshock transient, forms. Sometimes, the upstream compressional boundary can further steepen into a secondary shock, which has been observed to accelerate particles and contribute to the primary shock acceleration. However, secondary shock formation conditions and processes are not fully understood. Using particle-in-cell simulations, we reveal how secondary shocks are formed. From 1D simulations, we show that electric fields play a critical role in shaping the shock's magnetic field structure, as well as in coupling the energy of hot ...