Form within a Form

Open to all! Ask other shopowners for help.
Post Reply
ArtcoInc
Contributor
Posts: 119
Joined: Fri Oct 25, 2019 4:19 pm
Phoenix Version: v1.0.3.0
Has thanked: 86 times
Been thanked: 17 times

Form within a Form

Post by ArtcoInc »

Prior to Phoenix v1.0.8.0, the product_info.php file was basically an empty form, containing an envelope, into which all the pi modules were loaded.

I'm working with an old add-on (one Burt wrote many years ago) in an older version of Phoenix (please don't judge), that, while viewing an item in the product_info.php page, allows a customer to enter an email address to be notified when an item is back in stock. The add-on uses a form (within the product_info form) to collect and record the email address. This form-within-a form is creating a problem.

1) As written, when the customer submits their address, product_info.php either:
a) ignores saving the email address, and if there are no attributes, records the submission as 'add to cart', or
b) ignores saving the email address, and prompts for any needed attribute.

In both cases, the email address is not recorded.

2) If I delete the opening <form> code in product_info.php (but leave the closing <form>), the customer's address submission is recorded. But, nothing is recorded when the 'Add to Cart' button is clicked.

3) If I then add an opening <form> tag to the beginning of the 'buy_button' code, when the 'Add to Cart' button is clicked, the item is added to the cart IF there are no item attributes. But if there ARE attributes to select, than nothing is added to cart.

4) If I then add another opening <form> tag to the beginning of the 'options_attributes' code, clicking the 'Add to Cart' button adds the item to the cart (both with and without attributes).

( If I leave the opening <form> tag to the beginning of the 'options_attributes' code, but remove it from the beginning of the 'buy_button' code, clicking the 'Add to Cart' button ONLY works with items with attributes (that have been correctly selected), and NOT for items without attributes.)

And, if the customer also selected to be notified (don't know why, since the item is in stock, but checking anyway), the email address is also recorded.

So, while this (#4) 'works' the way I want, the generated HTML code has lots of 'red flags' ... a form-within-a form, a stray end <form> tag, etc.

So, how can one have a form-within-a-form that works, and still generate clean code?

(I have considered putting the email address 'form' in a pop-up modal, and moving the actual code down into the footer (I've done that before))

I'm sure that there probably are other add-ons that do this, but I'm also using this as a learning experience :roll:

So, any ideas of how to deal with a form-within-a-form (short of upgrading to a newer version of Phoenix)? 8-)

TIA!

Malcolm


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4547
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Form within a Form

Post by burt »

ArtcoInc wrote: Tue Aug 19, 2025 6:06 pm I have considered putting the email address 'form' in a pop-up modal, and moving the actual code down into the footer (I've done that before)
This is the way.

A form within a form is not valid HTML.
I am not here to build for you.
I am here to build with you. Let's help each other.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply