public class ContactFormController { public string FirstName { set; get; } public String LastName { set; get; } public String Email { set; get; } public String Phone { set; get; } public Boolean disabl {set;get; } Contact con = new Contact(); // checking condition and passing value public ContactFormController() { disabl=true; } public void change(){ System.debug('Change is Running now'); if (String.isNotBlank(FirstName) && String.isNotBlank(LastName) && String.isNotBlank(Email) && String.isNotBlank(Phone)){ disabl = false; // If all fields are filled, enable the submit button } else { disabl = true; // If any field is empty, disable the submit button } } //saving into contact // public void insertAcc(){ try { con.FirstName = FirstName; con.LastName = LastName; con.Email = Email; con.Phone = Phone; insert con; } catch (Exception e) { // Handle the exception here System.debug('Error: ' + e.getMessage()); } // calling next vf page } }