why my form does not work

// start of the Form Form { TextField("First name", text: $first_name) TextField("Surname", text: $surname) TextField("Email", text: $email)

                    TextField("Phone Number", text: $phone_number)
                                .keyboardType(.phonePad)
                        .onChange(of: phone_number) { newValue in
                            // Handle phone number input change
                        }
                    
                    // Segment Picker
                                    Picker("Gender", selection: $gender) {
                                        ForEach(Gender.allCases) { gender in
                                            Text(gender.rawValue.capitalized).tag(gender)
                                        }
                                    }
                                    .pickerStyle(SegmentedPickerStyle())
                    
                    
                    DatePicker("Date of Birth", selection: $birth_date, displayedComponents: .date)
                    
                    Button(action: {
                        isShowingImagePicker = true
                    }) {
                        Text("Select Profile Picture")
                    }
                    .sheet(isPresented: $isShowingImagePicker) {
                        imagePicker(image: $profileImage)
                    }

                    if let image = profileImage {
                        Image(uiImage: image)
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 200, height: 200)
                    }

                  
                        TextField("Enter Username", text: $username)
                        SecureField("Password", text: $password)
                    
                    Toggle("Agree to Terms", isOn: $isCheckboxChecked)
                        
                        .toggleStyle(SwitchToggleStyle())

                     
                    
                    Button(action: {
                        
                        if !first_name.isEmpty && !surname.isEmpty && !email.isEmpty && !phone_number.isEmpty && !username.isEmpty && !password.isEmpty {
                           
                        guard let url = URL(string: "https://example.com/signup.php") else { return }
                            var request = URLRequest(url: url)
                            request.httpMethod = "POST"
                            request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
                            
                            let dateFormatter = DateFormatter()
                            dateFormatter.dateFormat = "yyyy-MM-dd"
                            let formattedBirthDate = dateFormatter.string(from: birth_date)
                            
                            let parameters: [String: Any] = [
                                "first_name": first_name,
                                "surname": surname,
                                "email": email,
                                "phone_number": phone_number,
                                "gender": gender.rawValue,
                                "password": password,
                                "birth_date": formattedBirthDate,
                                "username": username,
                                "profile_image": profileImage ?? UIImage()
                            ]
                            
                            let parameterString = parameters.map { key, value in
                                return "\(key)=\(value)"
                            }.joined(separator: "&")
                            
                            request.httpBody = parameterString.data(using: .utf8)
                            
                            URLSession.shared.dataTask(with: request) { data, response, error in
                                if let error = error {
                                    print("Error: \(error.localizedDescription)")
                                } else if let data = data {
                                    let responseString = String(data: data, encoding: .utf8)
                                    print("Response: \(responseString ?? "")")
                                }
                            }.resume()
                            
                            // Perform sign-in logic here
                         
                        } else {
                               message = "Fill all required fields"
                               showingAlert = true
                           }
                        
                    }, label: {
                        Text("Sign In")
                            .foregroundColor(.white)
                            .frame(width: 300, height: 50, alignment: .center)
                            .background(Color.red)
                            .cornerRadius(10)
                            .padding(.top)
                      
                    }).buttonStyle(PlainButtonStyle())
                    
                }
                //end of the form
                
            }.frame(width: .infinity, height: 580)
             .foregroundColor(.wangoColorGray)
            .background(Color.white)
            .cornerRadius(10)
            .padding(.horizontal)
            
            //End of Sign up box
            
        }

Provide more specifics on what you mean by "form does not work". What do you expect to see? What do you see when you run your app?

I suggest moving your networking code out of the form into its own function. Call the function when someone taps the Sign In button.

why my form does not work
 
 
Q