vozzek Posted December 7, 2007 Share Posted December 7, 2007 Hi all, Okay, I know you can't nest forms within each other. However, I need to understand how other pages get around the problem on my checkout page. It's more visual than anything, so here's a screenshot: My <forms> are marked in red. The yellow boxes represent <tables>. Form 1 contains some info in that textbox that I need to post to the next page. The button that posts the form is wayyyyy down at the bottom of the page. But in between, I need another small form to accomplish the adding of a gift certificate (form 2). Where do I put the <form> tags to get around this? Do I really have to move my textbox to the bottom of the page (or swap those forms left/right so I'm not overlapping). How do other pages get past this? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 I would just eliminate form2 and use a button with a onclick event to add the gift certificate value to a hidden field (use JavaScript in the onclick event of the button - I assume you are for your gift certificate). example: <script language="javascript"> function agv(amount) { document.getElementById('gca').value = document.getElementById(amount).value; } function add() { document.getElementById('giftrequest').value = document.getElementById('gca').value; } </script> <form name="form1" action="whatever.php" method="post"> <input type="radio" id="gift1" value="$25" onclick="agv(this.id)" name="gift"> $25 <input type="radio" id="gift2" value="$50" onclick="agv(this.id)" name="gift"> $50 <input type="radio" id="gift3" value="$75" onclick="agv(this.id)" name="gift"> $75 <input type="radio" id="gift4" value="$100" onclick="agv(this.id)" name="gift"> $100 <input type="radio" id="gift5" value="$200" onclick="agv(this.id)" name="gift"> $200 <input type="hidden" id="gca"> <input type="hidden" id="giftrequest" name="giftcertificate"> <input type="button" value="Add to Order" onclick="add()"> </form> Be sure you do not validate "gift" radio button value; it's just named for functionality purposes. The only field you should validate for the script above is "giftcertificate" hidden field value. Quote Link to comment Share on other sites More sharing options...
dbo Posted December 8, 2007 Share Posted December 8, 2007 phpQuestioner's approach is not a bad one, but beware if your users do not have javascript enabled this will not work. What you might consider is just using the single form (as phpQuestioner mentioned) and then testing to see which button was clicked and then processing the form appropriately from there. if( isset($_POST['update']) ) { //Process update cart code } else if( isset($_POST['checkout']) ) { //Process checkout code } else if( isset($_POST['add_to_order']) ) { //Process add to order code } else { //Error } Of course if those are image buttons you'll have to do it a little differently, but that's the main idea. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 dbo is correct - your viewers will have to have JavaScript enabled on their browser for my idea to work, but a vast majority or most internet users have JavaScript enabled on their browsers. if you think that maybe be a problem; that it might exclude a small amount of internet users - require the user to have JavaScript enabled on there browser or rediect them to an error page; that tells them they must have JavaScript enabled on their browser to view your website/web page. example: <noscript> <meta http-equiv="refresh" content="1;error-page.html"> </noscript> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 9, 2007 Share Posted December 9, 2007 this is a styleing issue... you should NEVER nest forms - it invalidates your html... to get that form on teh left of the form 1 you simply float form 2 to the right. Quote Link to comment Share on other sites More sharing options...
dbo Posted December 9, 2007 Share Posted December 9, 2007 I would suggest doing it with a single form... however you decide to do it. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 9, 2007 Share Posted December 9, 2007 doing it with a single form would require you to put in an extra check to see which type of data has been sent and what to do with it - having 2 forms also means it is easier to direct the information to the correct script... keep each form that requires different processing separate SEPARATION HELPS MAINTENANCE... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.