susanBuck / e15-spring22

0 stars 0 forks source link

Form/Multiple Actions #44

Closed YvaGithub closed 2 years ago

YvaGithub commented 2 years ago

Hello everyone, I was wondering if there is a way to make a form trigger multiple actions once the submit button is pressed. For example, can search for an item, make some selections in a checkbox and provide an email address at the same time. I know it has been done; I just couldn't do it myself. Anticipated thanks for your input, Yvaral

susanBuck commented 2 years ago

Hi @YvaGithub -

Yes, you can accomplish multiple "tasks" when processing a form. You would write the code to do this in the method processing the form. E.g.:

public function process() 
{
    # Complete task 1...
    # Complete task 2...
    # Complete task 3...
    # Etc...
}

But things like selecting a checkbox would happen in the displaying of the form, not processing. And I'm not exactly sure what you mean by providing an email address. If you have a specific example we could work from, that might help clarify things.

YvaGithub commented 2 years ago

Thanks for the response. By providing email, I meant let's say you are asked to provide your email on the form so you can receive coupons for future purchases. When you click submit, I assume that the email you provided should be saved somewhere and can be retrieved.

susanBuck commented 2 years ago

@YvaGithub - Gotcha, I see what you mean. Knowing that, the above example would be modified to something like this:

public function process() 
{
    # Complete task 1, for example persist email address to appropriate table in the database
    # Complete task 2
    # Complete task 3
    # Etc...
}

FYI We'll talk about persisting data to a database next week. : )

YvaGithub commented 2 years ago

I am looking forward to learning it. Thank you