Boerie Posted July 19, 2009 Share Posted July 19, 2009 Hi all. I'm working on a real estate website for a customer. i have this form in php, but i want to change it to a nicer one. the first form uses a dropdown list to select the types of properties. wich happens in the code : <select name="pt" size="1" style="height: 18px; width:125px;"> <option value="" selected="selected"><?php echo FORM_SELECT_ALL_TYPES; ?></option> <?php $rows = $sql->execute ( "SELECT * FROM " . $propertytypes_table . " ORDER BY propertytype ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "id" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "propertytype" ] ); ?> </option> <?php } ?> </select> but i want to format the dropdownlist to a set of checkboxes as in my design on the following link : http://antwerpfashionagency.com/immo/new/index.html?loc=ikZoek now i thought this would be easy and made the folowing code <?php if($display_search_types == "Y") { ?> <h3>Checkboxes</h3> <label><input type="checkbox"><?php echo FORM_SELECT_ALL_TYPES; ?></label> <?php $rows = $sql->execute ( "SELECT * FROM " . $propertytypes_table . " ORDER BY propertytype ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; if ($i % 2 == 0 ) { <div class='leftcol'> <label> <input type='checkbox'><?php echo $cgi->htmlEncode ( $row [ 'propertytype' ] ); ?> </label> </div> } else { <div class='rightcol'><label><input type='checkbox'><?php echo $cgi->htmlEncode ( $row [ 'propertytype' ] ); ?></label> </div> } ?> <?php } ?> but this doesn't seem to work. had anyone an idea to make this work ? thanks in advance, Kristof ! Link to comment https://forums.phpfreaks.com/topic/166555-need-some-help-rebuilding-form/ Share on other sites More sharing options...
patrickmvi Posted July 20, 2009 Share Posted July 20, 2009 You name to add names and values to your input tags. Without those, there is no way for the browser to identify what each checkbox means. Your best bet would be to set it up something like this: <input type="checkbox" name="proptypes[]" value="(WHATEVER IDENTIFIER IDENTIFIES A TYPE)"> <input type="checkbox" name="proptypes[]" value="(WHATEVER IDENTIFIER IDENTIFIES A TYPE)"> <input type="checkbox" name="proptypes[]" value="(WHATEVER IDENTIFIER IDENTIFIES A TYPE)"> This sort of setup would provide an array named "proptypes" which would contain all of the identifiers for the checked boxes. Link to comment https://forums.phpfreaks.com/topic/166555-need-some-help-rebuilding-form/#findComment-878619 Share on other sites More sharing options...
Boerie Posted July 20, 2009 Author Share Posted July 20, 2009 Something like this ? The problem is when i run this he give : 1 A 2 B instead of apartment and bungalow <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>FancyForm - Javascript checkbox replacement</title> <meta name="description" content="FancyForm is a powerful checkbox replacement script used to provide the ultimate flexibility in changing the appearance and function of HTML form elements."> <meta name="keywords" content="html,css,javascript,checkbox,button,style,form"> <script src="javascripts/niceforms.js" type="text/javascript"></script> <link rel="stylesheet" href="css/screensmall.css" type="text/css" media="screen"/> <link href="css/niceforms.css" rel="stylesheet" type="text/css" /> <?php require ( "includes/config.php" ); require ( "includes/CGI.php" ); require ( "includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } require ( "includes/CSQL.php" ); require ( "includes/lang/" . $language_pack . "/index.php" ); ?> </head> <body> <hr id="example"> <div class='section demo'> <h2>Ons aanbod</h2> <form method="get" action="<?php echo "$template_page_name"; ?>" class="niceform"> <input name="op" type="hidden" value="search" /> <?php if($display_search_types == "Y") { ?> <h3>Checkboxes</h3> <label><input type="checkbox"><?php echo FORM_SELECT_ALL_TYPES; ?></label> <?php $rows = $sql->execute ( "SELECT * FROM " . $propertytypes_table . " ORDER BY propertytype ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; if ($i % 2 == 0 ) { $left = $rows [ $i ] ; } else { $right = $rows [ $i ]; } ?> <?php } ?> <?PHP foreach($left as $left_box) { echo '<div class="leftcol">'; echo '<label><input type="checkbox" value="'; echo $cgi->htmlEncode ( $left_box[ "id" ] ); echo'">'; echo $cgi->htmlEncode ( $left_box[ "propertytype" ] ) ; echo '</label>'; echo '</div>'; } ?> <?PHP foreach($right as $right_box) { echo '<div class="rightcol">'; echo '<label><input type="checkbox" value="'; echo $cgi->htmlEncode ( $left_box[ "id" ] ); echo'">'; echo $cgi->htmlEncode ( $right_box[ "propertytype" ] ); echo '</label>'; echo '</div>'; } ?> <br /> <div style="padding-top:10px"><h3>Zoekcriteria</h3></div> <span>In gemeente:</span> <br /> <?php } if($display_search_locations == "Y") { ?> <select class="width_160" name="City" id="Select2" style="text-align:center;"> <option value="" selected="selected"><?php echo FORM_NO_PREFERENCE; ?></option> <?php $rows = $sql->execute ( "SELECT * FROM " . $propertylocations_table . " ORDER BY propertylocation ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "id" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "propertylocation" ] ); ?> </option> <?php } ?> </select> <?php } ?> <?php if (($display_rental & $display_sale) == "Y"){ echo "<input name=\"po\" type=\"radio\" value=\"S\">For Sale<br> <input name=\"po\" type=\"radio\" value=\"R\">For Rent<br>"; } elseif (($display_rental) == "Y"){ echo "<input name=\"po\" type=\"hidden\" value=\"R\">"; } elseif (($display_sale) == "Y"){ echo "<input name=\"po\" type=\"hidden\" value=\"S\">"; } ?> <div style="text-align:center"><input type="submit" value="TOON ZOEKRESULTATEN" class="buttonSubmit" style="text-align:center"/> </form> <script type="text/javascript" src="javascripts/mootools.js"></script> <script type="text/javascript" src="javascripts/moocheck.js"></script> </body> </html> Link to comment https://forums.phpfreaks.com/topic/166555-need-some-help-rebuilding-form/#findComment-878986 Share on other sites More sharing options...
Boerie Posted July 20, 2009 Author Share Posted July 20, 2009 nvm solved. Link to comment https://forums.phpfreaks.com/topic/166555-need-some-help-rebuilding-form/#findComment-879037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.