Jump to content

Recommended Posts

if(isset($_GET['cat'])){
$cat=$_GET['cat'];
$cat2=$_GET['cat'];
$cat=str_replace("-"," ", $cat);


if(isset($_GET['num_products']) && ctype_digit($_GET['num_products'])){
$num_products_per_page=(int)$_GET['num_products'];
$_SESSION[$cat2]['num_products_per_page'] = $num_products_per_page;
$num_products_per_page = stripslashes($num_products_per_page);
$num_products_per_page = mysql_real_escape_string($num_products_per_page);
}
else{
$num_products_per_page="20";
}
$num_products='
<form action="" method="GET">
  <label>Display:</label>
  <select id="num_products" onchange="this.form.submit();" disabled="disabled">
    <option value="8">8 Items per Page</option>
    <option value="12">12 Items per Page</option>
    <option value="16">16 Items per Page</option>
<option value="20" selected="selected">20 Items per Page</option>
    <option value="24">24 Items per Page</option>
<option value="32">32 Items per Page</option>
    <option value="40">40 Items per Page</option>
<option value="48">48 Items per Page</option>
  </select>
<noscript>
<input type="submit" value="Go" />
</noscript>
</form>
';

if(isset($_GET['sort_by'])){
$sort_by_selected=$_GET['sort_by'];
$_SESSION[$cat2]['sort_by_selected'] = $sort_by_selected;
$sort_by_selected = stripslashes($sort_by_selected);
$sort_by_selected = mysql_real_escape_string($sort_by_selected);
if(isset($sort_by_selected)){
$sort_by_selected2=$sort_by_selected;
if($sort_by_selected2=="product_price_hl"){
$sort_by_selected2="ABS(product_price) DESC";
}
elseif($sort_by_selected2=="product_price_lh"){
$sort_by_selected2="ABS(product_price) ASC";
}
}
}
else{
$sort_by_selected2="product_id";
}
$sort_by='
<form action="store.php?cat='.$cat2.'" method="GET">
<label>Sort By:</label>
  <select id="sort_by" onchange="this.form.submit();">
    <option value="relevance">Relevance</option>
    <option value="product_price_hl">Price: High to Low</option>
    <option value="product_price_lh">Price: Low to High</option>
  </select>
<noscript>
<input type="submit" value="Go" />
</noscript>
</form>
';
}
else{
header("Location: ./index.php");
}

 

For some reason the Sort By: form is redirecting to index.php...

Link to comment
https://forums.phpfreaks.com/topic/238521-form-submit-redirecting-unexpectedly/
Share on other sites

But it is, because it's being set directly in the form action.

 

 

http://ghosthuntersportal.com/store.php?cat=emf-meters

 

Select another option from the Sort By: drop down, when it reloads it heads to index.php. It clearly defined in the form action as I viewed the page source code generated and it's there.

No it isn't. Just look at the URL in the address bar after changing the sort option, and you can see that it is no longer there. Why do you have two separate sets of <form></form> tags in that script?

 

 

No it isn't. Just look at the URL in the address bar after changing the sort option, and you can see that it is no longer there. Why do you have two separate sets of <form></form> tags in that script?

 

I can't see the URL in the address bar, because it takes off to index.php.

 

And what do you mean two sets? One's for the Sort By form and the other for Display form.

Well, when any JS is involved, I'm inclined to defer to someone who knows it better than I do, which is what I need to do here . . . Sorry I can't take this one to a resolution, but Im sure someone here will be able to help out.

 

EDIT: if it was me however, I'd get it working as desired without using any onchange= or JS, then add it after it was behaving the way I want.

Surprisingly, the following link/answer is from a previous thread by the OP - http://www.phpfreaks.com/forums/index.php?topic=334223.msg1573995#msg1573995

 

Programming involves a huge amount of consistency and continuity. Something that worked before for a particular reason, will work the same way the next time you do it in the same situation.

To be honest I forgot about that last thread.

 

Anyway, I had tried the input hidden prior to starting this thread, and it didn't work. I just tried it again to be sure, and it's not working. That's the current active method being used here:

 

http://www.ghosthuntersportal.com/store.php?cat=emf-meters

I got it to work when I added the name attribute to the select and input tags.... However, if I'm not mistaken the name attribute was deprecated in favor of the id attribute. So is this a error in the existing version of XHTML 1.1? It should be processing id as it had previously processed name.

 

http://www.w3.org/TR/xhtml1/#h-4.10

I got it to work when I added the name attribute to the select and input tags.... However, if I'm not mistaken the name attribute was deprecated in favor of the id attribute. So is this a error in the existing version of XHTML 1.1? It should be processing id as it had previously processed name.

 

http://www.w3.org/TR/xhtml1/#h-4.10

 

Re-read what it says.  Only the name attribute for those particular elements has been deprecated.  Note that input is not on the list.

Unless you plan on serving your pages as XML, there's no real point in writing XHTML anyway.  XHTML is essentially dead.  It never went anywhere, and I doubt there will ever be a new version of it.  Stick with HTML 4.01, with some HTML 5 enhancements.  It's far easier regarding doctype.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.