checking $_SESSION inside HTML form and branching depending on outcome

Existing code in HTML allows the visitor to order the item shown in accompanying image. The existing code uses a form and an “Order” button created with an input field (type=”submit”) to send the appropriate size, price, discount and other fields to a Yahoo store for processing.

I need to alter this code so that it checks for the user to be logged in either prior to the visitor clicking the “Order” button (checking $_SESSION inside PHP) or AS they click the “Order” button (onclick). If the user is not logged in, the visitor needs to be redirected to the login/register page so that they can join the organization and then return them to the product page they were on previously. If they are successfully logged in already, it should submit the form and send the variables to the Yahoo store. The Yahoo store code works and I don’t expect anyone to know and/or troubleshoot it, but I need an idea on how best to:
1) check to determine if the visitor is logged in,
2) if logged in, specify that the “Order” button is type=”submit” (as it is currently)
3) if not logged in, specify that the “Order” button reads “Login” and when clicked, redirects the visitor to the login_logout.php routine (popup), then returns the visitor to the previous where they now see the “Order” button in its original state and can place the order. Note: session_start(); is being handled in another PHP file called ‘login_logout.php’.

The area that I'm working with is the <p class="submit"> paragraph.

Original HTML code:

<form action="<!--#ystore_order id=ae009 -->" method="post">
  <h1><!--#ystore_catalog id=ae009 field=name --></h1>
  <div class="productImage">
    <!--#ystore_catalog id=ae009 field=image format=html -->

  <div class="order">
   <p class="salePrice">
  <em>For Sale Price:</em>
  Enter your <a href="" target="_blank"     class="external">promo code  </a> at checkout
   <p class="regularPrice"><em>Regular Price</em> <!--#ystore_catalog id=ae009 field=price format=html --></p>
   <p class="options"><!--#ystore_catalog id=ae009 field=options format=html --></p>
   <p class="sole"><!--#ystore_catalog id=ae009 field=sole --></p>
   <p class="size">
       <a onclick="MM_openBrWindow('../../Size_Chart.html','SizeChart1','width=910,height=255')"><!--#ystore_catalog id=ae009 field=size --></a> 
   <p class="size">*Validate width/size availability</p>
   <p class="submit">
      <input type="submit" value="Order" />

  <h2 class="manufacture"><!--#ystore_catalog id=ae009 field=name --></h2> 
  <p class="style"><em>Style</em> <!--#ystore_catalog id=ae009 field=label --></p>
  <p class="description"><!--#ystore_catalog id=ae009 field=caption --></p>
  <p class="link"><a href="<!--#ystore_catalog id=ae009 field=productlink -->" target="_blank" class="external">Additional Product Information</a></p>

Here is what I thought to do:

<form ...>               
  <div class="order"...>
     ....... additional lines of code .......
   <p class="submit">
      <?php if($_SESSION['logged_in']) {    ?>
        <p><input type="submit" value="Order" /></p>
      <?php } else { ?> 
        <p><input type="button" src="" value="Login" /></p>
      <?php } ?>
  <...miscellaneous irrelevant bs...>

However, when I do this inside the form statement it doesn’t seem to work. Am I anywhere near the right approach here? I’m aware that I’m dealing with a client-side function using a server-side language, but if I’m just checking for the $_SESSION status, does this matter? I looked through as many of the other FAQ’s as I could find that had anything to do with PHP inside a form statement, also considered calling a PHP function from an onclick=”zzzzz.js” directive in the Input field statement. Nothing seem to work or directly be applicable to my scenario. Thanks in advance for any help.

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.