close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Add to Cart Button and Show If Feature

Thread began 7/12/2010 10:37 pm by mora398588 | Last modified 7/26/2010 6:55 pm by Jason Byrnes | 2015 views | 13 replies |

mora398588

Add to Cart Button and Show If Feature

I received a comment from a public user of our website, when registering for a workshop, stating that his shopping experience on our site was not user-friendly (see following page [hrworkshops.php]).

The user stated that he did not like how the webpage redirected him to the workshop registration page rather than to the cart page. He expressed interest in adding additional workshops to his shopping cart.

I understand how to modify the add to cart button to redirect a user to the cart.php page, but I will eventually need the user to register for the workshop using our registration form. The way it is currently setup, the user clicks the add to cart button and is redirected to the registration form where, when completed, the user is redirected to the cart page where he or she can complete the shopping process.

However, is it possible to keep the user from having to go back and repeat this process for each workshop? Ideally, I would like the user to add more than one workshop to the cart, and, when finished, be taken to the registration form and then redirected to the cart page to complete the shopping experience. Is this possible? Could this be accomplished by creating a Show If Region whereby the user would click the add to cart button and a Show If Regions would appear below the add to cart button revealing another button that coule redirect them to the registration page (when ready), while saving the workshops added to the cart within the session? That way, the user may be able to add more than one workshop to their cart while not leaving the page, and when finished, he or she could click the revealed button in the Show If Region to complete the shopping experience.

I have seem similar setups, such as Costco.com. Costco's website, when clicking on their add to cart button, reveals a view cart button on the same page, just below the add to cart button. This appears to allow the user to save their items in the shopping cart while not leaving the page.

Sign in to reply to this post

Eric Mittman

You can setup your add to cart experience however you would like it to be. If you would like to add the item to the cart but not take the user to a page you can keep them on the same page. Your show region could just be a check for items in the cart or a particular item in the cart. This part would need to be custom coded though. You could then show a button to register or view the cart or whatever you would like.

If you have the ability to know when the registration has been filed out then you can just display a button on the cart page to register if it has not been completed already. You would also need a check before the user checks out to determine if the registation has not occurred, if it has not then you would need to prompt them to register before finishing the checkout.

Sign in to reply to this post

mora398588

Eric,

Thank you for your reply. Can I user SecurityAssist to create a rule to compare the pressing of the add to cart button to an item being added to the cart, followed by inserting a show region server behavior?

If so, would you be able to provide some assistance in setting up the rule? I researched this topic in your forums and on the Internet and I cannot seem to find a solution.

As always, your assistance is greatly appreciated!

Sign in to reply to this post

Eric Mittman

It might be possible to do it with some Security Assist rules like this but it would be more difficult and take more time to do it like that. Based on the descriptions that I posted how exactly would you like the user experience to work? If you can spec out the functionality that should occur it will be much easier to craft the logic that gives you that experience.

Sign in to reply to this post

mora398588

Functionality

Eric, thank you again for your assistance.

Here is how I am envisioning this to work: (reference [hrworkshops.php])

1. When the user clicks the "Add to Cart" button, I would like a show region to appear just below the "Add to Cart" button stating something like, "Your item has been added to the cart. Click here to go to the shopping cart."

Ideally speaking, I would like to offer the user the opportunity to shop around and add more workshops or items to their shopping cart before making the decision to move on to the next step; the next step being either going to the shopping cart or filling out the registration form.

2. When the user is done shopping or adding other workshops or items to their cart, they can click on the link in the show region to move on to the next step (cart of filling out the registration form). I am assuming that this can be done since the workshops being added to the cart are retained within the Session.

Sign in to reply to this post

Eric Mittman

I can think of a couple of ways you could handle some things like this. The first part of this is to make it so that if you add the item to the cart a message displays letting the user know that the item has been added to the cart, there will also be a button to allow the user to proceed to the cart.

To do this you should set the redirect page in your add to cart server behavior to go back to this same page with a URL parameter present. So the end of the redirect might have this in it:

?added=1

Then you would add in your message and the button where you would like the user to see it after adding the item to the cart. Once you have the message and the button there you would add in an if statement around this part so that it is only displayed if the added url parameter is set to one. Here is what that if statement would look like:

php:
<?php if(isset($_GET['added']) && $_GET['added'] == 1){ ?>

your message and button code go here

<?php ?>



Once this part is done you can move onto the next part. So when the user clicks on the button to go to the cart you would like them to fill in the registration information first correct? If this is the case then you will send the user to the cart page. Then on the cart page you will check to see if they have filled in this information. If they have not they will be redirected to the page that will gather this info. If they have filled in the information then they can proceed to the cart and checkout.

To do this your registration form page will need to store the information in your db, then set a session variable. Then on the cart page you just check this session variable so see if it has been set to the predetermined value. If it has then the user will stay on the cart page. If this session variable does not exist or does not have the correct value then you would have a header call that would redirect the user to the registration page.

The set session value on the registration page should set a session variable to a particular value when the information is inserted into the db.

On the cart page you would add in an if statement to check on this session variable, if it is not set correctly you would redirect them to the registration page. Here is an example of what that code would look like.

php:
<?php
if(!session_id()) session_start();
if(!(isset(
$_SESSION['registered'])) || $_SESSION['registered'] != 1){
  
header("Location: registration.php");
}
?>
Sign in to reply to this post

mora398588

Eric,

Thank you for taking the time to provide me the logic to set this up. Things are looking great! Your assistance has been most valuable.

I do have another question related to this topic. This is pertaining to when the user clicks on the "Add to Cart" button. I noticed that after the user clicks on the "Add to Cart" button, the page is redirected back to itself, but it takes the user to the top of the page, as well as to its beginning.

To better explain, I am using a repeat region that displays up to 3 workshops at a time. I have added navigation links to get the user to navigate through the various workshops we currently offer. When the user clicks on the "Add to Cart" button, the user is immediately redirected to the initial workshop page, even though the user may have been on, lets say page 3, of the workshop site.

My question is, how can I modify the code to redirect the user back to the same page or location from which they clicked the "Add to Cart"?

Ideally, I would like the user not to have to navigate back to where they were.

Thank you.

Sign in to reply to this post

Jason ByrnesWebAssist

add a named anchor just before the add to cart button form and change the add to cart button forms action to use the named anchor:

php:
<a name="button1" id="button1"></a>

<form name="eCart2_1_ATC_0" method="POST"  action="<?php echo $_SERVER["PHP_SELF"]; ?>#button1<?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""?>">
Sign in to reply to this post

mora398588

Anchor Not Working

Hello, Jason...

I created the named anchor and changed the form action code based on your example. It did not work. What I got back was a broken web page; images and text were missing after the add to cart button was pressed.

I have attached a copy of my web page file for your review.

Thank you for your time.

Attached Files
hrworkshops.zip
Sign in to reply to this post

Jason ByrnesWebAssist

I see the named anchor, but I do not see where the forms action was changed.


edit:

php:
<a name="button1" id="button1"></a>
          <form name="eCart1_2_ATC_<?php echo $row_rs_Workshops["PresentID"]; ?>" method="POST"  action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""?>">




to:

php:
<a name="button<?php echo $row_rs_Workshops["PresentID"]; ?>" id="button<?php echo $row_rs_Workshops["PresentID"]; ?>">&nbsp;</a>
          <form name="eCart1_2_ATC_<?php echo $row_rs_Workshops["PresentID"]; ?>" method="POST"  action="<?php echo $_SERVER["PHP_SELF"]; ?>#button<?php echo $row_rs_Workshops["PresentID"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""?>">
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...