Enjoy an ad free experience by logging in. Not a member yet?
Register .
06-02-2009, 04:06 PM
PM User |
#1
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
using a form to run a php page???
Hi all,
ok i have been using js to have a dropdown list on my page and when the value changes it runs a function on a php page and changes the data onscreen via ajax
the problem i have is its not user friendly to those who dont have js enabled and 2 its giving me a validation error because im not using the action tag within my form
here is my form code
PHP Code:
<form>
<div class="storefilter">
<b>Filter Brands By:</b>
<select name="cds" onchange="showCD(this.value)">
<?php
$options =array( 'entertainment' , 'computing' , 'electronics' , 'clothing' , 'misc' );
foreach( $options as $option ){
if(isset( $_SESSION [ 'page_category' ]) && $_SESSION [ 'page_category' ]== $option )
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ;
else
echo "<option value=\"{$option}\">{$option}</option>" ;
} ?>
</select>
</div>
</form>
and here is the getcd.php page
PHP Code:
<?php
session_start ();
$q = $_GET [ "q" ];
if(isset( $_SESSION [ 'page' ])){
$page = $_SESSION [ 'page' ];
}
if ( $page == "stores" ){
$querystring = "category = '$q' ORDER BY storeName ASC" ;
}
elseif( $page == "brand" ){
$querystring = "category = '$q' AND isbrand = '1' ORDER BY storeName ASC" ;
}
ini_set ( 'display_errors' , 1 );
ini_set ( 'display_startup_errors' , 1 );
error_reporting ( E_ALL ); ?>
<link rel="stylesheet" type="text/css" href="stylesheets/main_category_stores.css"/>
<link rel="stylesheet" type="text/css" href="css/rating.css"/>
<?php
require_once( 'dbinfo.php' );
require( '_drawrating.php' );
if (! $db_found ) {
die( 'Could not connect: ' . mysql_error ());
}
mysql_query ( "SET NAMES 'utf8'" );
$stores = "SELECT *
FROM stores
WHERE $querystring" ;
$query = mysql_query ( $stores );
while ( $row = mysql_fetch_array ( $query )){
$name = $row [ 'name' ];
$storename = $row [ 'storeName' ];
?>
<div class='storecontainer'>
<div class='storeheader'>
<?php print '<img src="' . $row [ 'logo' ] . '"
alt="' . $row [ 'storeName' ] . '"
title="' . $row [ 'storeName' ] . '" />' ; ?>
<div class='featuredRating'>
<?php print rating_bar ( $name . 'total' , '5' , 'static' ); ?>
</div>
</div>
<div class='desccontainer'>
<div class='storedesc'>
<?php echo htmlspecialchars ( $row [ 'description' ]); ?>
</div>
<div class='dc_availability'>
<?php
$getcodes = "SELECT *
FROM codes
WHERE storeID = '$name'
AND expireDate >= CURDATE()" ;
$query2 = mysql_query ( $getcodes );
if(! $query2 ){
die( mysql_error ());
}
$rows = mysql_num_rows ( $query2 );
if ( $rows <> 0 ){ ?>
<a href="discount.php?sID=<?php print $row [ 'name' ]; ?> "<img src="images/discount.png" alt="Discount Codes Available Click To See Details" title="Discount Codes Available Click To See Details" border="0" /></a>
<?php }
else {
}
?>
</div>
</div>
<div class='divider'></div>
<div class='storeinfo_link'>
<div class='storeimg'>
<a href="rate.php?sID=<?php print $row [ 'name' ]; ?> ">
<img src="images/ratestore.png"
alt="<?php 'Rate ' . $row [ 'storeName' ]; ?> "
title="<?php print 'Rate ' . $row [ 'storeName' ]; ?> "
border="0" /></a>
</div>
<div class='visitstore'>
<a href="<?php print $row [ 'storeLink' ]; ?> ">
<img src="images/visitstore.gif"
alt="<?php 'Visit ' . $row [ 'storeName' ]; ?> "
title="<?php print 'Visit ' . $row [ 'storeName' ]; ?> "
border="0" /></a>
</div>
</div>
</div>
<?php
} ?>
</div>
how do i add an action to this to make it do the same thing without using the js, i would also like to know how i can set up a check to see if the user has js enabled or not and how to set it up if the check fails or not???
thanks
Luke
Last edited by LJackson; 06-03-2009 at 02:16 PM ..
06-02-2009, 04:10 PM
PM User |
#2
Senior Coder
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
In PHP the form needs a place to go. Using either a GET or POST method. For submitting data you'd use this.
PHP Code:
< form action = "index.php" method = "POST" >
For getting data you'd use this.
PHP Code:
< form action = "index.php" method = "GET" >
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
06-02-2009, 04:18 PM
PM User |
#3
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
hi mate ok,
now do i remove
PHP Code:
< select name = "cds" onchange = "showCD(this.value)" >
and do i set the action to the php where the showCD(this.value) function is or just have the action set to showCD(this.value)
this is what i have now
PHP Code:
<form action="getcd.php" method="GET"> <div class="storefilter"> <b>Filter Brands By:</b> <select name="cds"><?php $options =array( 'entertainment' , 'computing' , 'electronics' , 'clothing' , 'misc' ); foreach( $options as $option ){ if(isset( $_SESSION [ 'page_category' ]) && $_SESSION [ 'page_category' ]== $option ) echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ; else echo "<option value=\"{$option}\">{$option}</option>" ; } ?> </select> <input type="submit" name="submit" id="submit" value="Submit" /> </div> </form>
which is getting the data but on its own on a newpage??? how do i get it to show on the same page as before???
thanks
mate
06-02-2009, 05:06 PM
PM User |
#4
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
Ok i have sorted it
here is the code
PHP Code:
<form action="brand.php" method="GET" target="_self"> <div class="storefilter"> <b>Filter Brands By:</b> <select name="category"><?php $options =array( 'entertainment' , 'computing' , 'electronics' , 'clothing' , 'misc' ); foreach( $options as $option ){ //if(isset($_SESSION['page_category']) && $_SESSION['page_category']==$option) //echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>"; //else if(isset( $_GET [ 'category' ]) && $_GET [ 'category' ]== $option ) echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ; else echo "<option value=\"{$option}\">{$option}</option>" ; } ?> </select> <input type="submit" name="submit" id="submit" value="Submit" /> </div> </form>
the benifits of this method are that it is accessible to everyone and i dont need the getcd.php page just had to change my code slightly and its working.
the only problem is that the page needs to refresh(i think, its not very noticable on my pc) but apart from that thats it
so how would i now set a check to see if the user has js enabled and if so run my previous code???
thanks
Luke
06-02-2009, 05:42 PM
PM User |
#5
Senior Coder
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
To check which browser their are using, you would use something like this. Try this.
PHP Code:
<?php
if ( strpos ( $_SERVER [ "HTTP_USER_AGENT" ], "MSIE" ) !== false ) {
?>
<center><b>You are using Internet Explorer, IDIOT!</b></center>
<?php } else { ?>
<center><b>You are not using Internet Explorer so you must be
smart!!</b><br>
(you are using:
<?php echo $_SERVER [ "HTTP_USER_AGENT" ]; ?>
)</center>
<?php } ?>
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
06-02-2009, 05:56 PM
PM User |
#6
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
how would the above check to see if js is enabled???
thanks
Luke
06-02-2009, 06:35 PM
PM User |
#7
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
Quote:
Originally Posted by
LJackson
how would the above check to see if js is enabled???
thanks
Luke
It won't and you don't need to. Keep your js like it is. Just make sure your form submits to somewhere. It might be easier to submit to the same php file that processes your ajax stuff. Just set it up to take form inputs. Using method="get" might be the easiest to do. If the user has js disabled the php will take over and run the php file that your ajax use to call. Helps if you try these things.
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
06-02-2009, 06:54 PM
PM User |
#8
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
believe me im trying these things but it takes a lot longer when your just guessing
i have tried it with js enabled and now without and it work pritty well needs ironing out as some things arnt working as they should but its getting there.
1 question how do i remove the submit button if js is enabled and show it if not?
cheers for your help so far
Luke
06-02-2009, 07:07 PM
PM User |
#9
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
You would have to do something like this
Code:
<noscript><div><input type="submit" name="submit" id="submit" value="Submit" /></div></noscript>
You need the div in there as elements inside of noscript tags need to be inside a block level element. You can make the div display:inline; if you like.
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
Users who have thanked _Aerospace_Eng_ for this post:
06-02-2009, 08:27 PM
PM User |
#10
Senior Coder
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
It wasn't to check if JS is enabled, it was to check which browser they were using.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
06-02-2009, 09:46 PM
PM User |
#11
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
Quote:
Originally Posted by
masterofollies
It wasn't to check if JS is enabled, it was to check which browser they were using.
ah right
thanks for your reply
Luke
06-02-2009, 10:07 PM
PM User |
#12
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
hi mate is it possible to include a noscript with-in a form so that i can have it perform different tasks if noscript is true?
here is something im trying
ok why is nothing working, i cant thank anyone nor can i use the tool bar above, is everyone experiencing this??? thanks
Luke
06-02-2009, 10:22 PM
PM User |
#13
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
ok your going to have excuse me for posting code without the php brackets but i cannot access anything
i'll try adding them myself
PHP Code:
<form action="brand.php" method="GET" target="_self">
<div class="storefilter">
<b>Filter Brands By:</b>
<select name="cds" onchange="showCD(this.value)">
<?php
$options =array( 'entertainment' , 'computing' , 'electronics' , 'clothing' , 'misc' );
foreach( $options as $option ){ ?>
<noscript><?php
if(isset( $_GET [ 'cds' ]) && $_GET [ 'cds' ]== $option )
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ;
else
echo "<option value=\"{$option}\">{$option}</option>" ;
?>
</noscript>
<?php
if(isset( $_SESSION [ 'page_category' ]) && $_SESSION [ 'page_category' ]== $option )
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ;
else
echo "<option value=\"{$option}\">{$option}</option>" ;
} ?>
</select>
<noscript><div><input type="submit" name="submit" id="submit" value="Submit" /></div></noscript>
</div>
</form>
it is working but when js is disabled it displays the form options twice so i would have each item in the list box listed twice which i dont want but im not sure how i can set it so that it check if noscript do this if not fo this??? can i simply use an if statment
like
PHP Code:
<?php if ?> <noscript><?php {
do this
}
else{
do that
}
would this work?
thanks
Luke
06-02-2009, 10:23 PM
PM User |
#14
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
No thats not how noscript works. Noscript is simply used to display some html or text if js is disabled. Why not just do this?
PHP Code:
<?php if((isset( $_GET [ 'cds' ]) && $_GET [ 'cds' ]== $option ) || (isset( $_SESSION [ 'page_category' ]) && $_SESSION [ 'page_category' ]== $option )) echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>" ; else echo "<option value=\"{$option}\">{$option}</option>" ; } ?>
instead of this?
Code:
<noscript><?php
if(isset($_GET['cds']) && $_GET['cds']==$option)
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
else
echo "<option value=\"{$option}\">{$option}</option>";
?>
</noscript>
<?php
if(isset($_SESSION['page_category']) && $_SESSION['page_category']==$option)
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
else
echo "<option value=\"{$option}\">{$option}</option>";
}?>
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
Last edited by _Aerospace_Eng_; 06-02-2009 at 10:25 PM ..
Users who have thanked _Aerospace_Eng_ for this post:
06-02-2009, 11:01 PM
PM User |
#15
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
DAMN and THANK YOU
why do i always over complicate things? lol
cheers for this,
1 other slight problem,
when i select either of the first two options with js disabled and click on submit it performs the check and displays the correct data but the default value of the listbox resets to the default value any ideas why this should happen, its fine with js enabled?
thanks mate
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 07:30 PM .
Advertisement
Log in to turn off these ads.