HTML中的現有代碼允許訪問者訂購伴隨圖像中顯示的項目。現有的代碼使用一個表單和一個使用輸入字段(type =「submit」)創建的「訂單」按鈕來發送適當的尺寸,價格,折扣和其他字段到雅虎商店進行處理。
我需要更改此代碼,以便在訪問者點擊「訂購」按鈕(在PHP中檢查$ _SESSION)之前檢查用戶是否要登錄,或者他們點擊「訂購」按鈕(onclick )。如果用戶未登錄,則訪問者需要重定向到登錄/註冊頁面,以便他們可以加入組織,然後將其返回到之前的產品頁面。如果他們已經成功登錄,它應該提交表單並將變量發送到雅虎商店。雅虎商店代碼的作品,我不希望任何人知道和/或疑難解答,但我需要一個想法如何最好: 1)檢查,以確定訪問者是否登錄, 2)如果登錄, 3)如果沒有登錄,指定「訂單」按鈕爲「登錄」,點擊後,將訪客重定向到login_logout.php。例程(彈出),然後將訪問者返回到先前的位置,他們現在可以看到處於其原始狀態的「訂單」按鈕,並可以下訂單。注意:session_start();正在另一個名爲「login_logout.php」的PHP文件中處理。
The area that I'm working with is the <p class="submit"> paragraph.
原始的HTML代碼:
<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>
<div class="order">
<p class="salePrice">
<em>For Sale Price:</em>
Enter your <a href="http://www.mydomain.com/coderequest.html" target="_blank" class="external">promo code </a> at checkout
</p>
<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>
<p class="size">*Validate width/size availability</p>
<!--******************************************************************************************-->
<p class="submit">
<input type="submit" value="Order" />
</p>
<!--******************************************************************************************-->
</div>
<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>
</form>
這是我想到了就去做:
<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="http://mydomain.com/login_logout.php" value="Login" /></p>
<?php } ?>
</p>
</div>
<...miscellaneous irrelevant bs...>
</form>
不過,我做這個形式語句中似乎當它不工作。我在這裏靠近正確的方法嗎?我知道我正在處理使用服務器端語言的客戶端函數,但是如果我只是檢查$ _SESSION狀態,這是否重要?我查看了許多其他常見問題解答,我發現它們與表單語句中的PHP有關,也考慮從輸入字段語句中的onclick =「zzzzz.js」指令調用PHP函數。似乎沒有任何工作或直接適用於我的方案。預先感謝您的幫助。
什麼價值'$ _SESSION [ 'LOGGED_IN']'攜帶登錄並沒有登錄 – itachi