I've succesfully managed to add custom fields to the customer. However I need these fields to show up in onepage checkout.
I've overridden Mage_Customer_Block_Widget_Name and created my own customer/widget/name.phtml, added the attributes in the sql/xxx_setup/installer-x.y.z.php (added them to adminhtml_customer, customer_account_edit, checkout_register and customer_account_create) and they work fine in the admin site, however they just wont work on the checkout form. The field shows up, but it has the wrong value and no label.
I'm clueless why does it work in the customer registration form but doesn't in the checkout.
The installer code to add the attribute is:
$attributes = array(
'lastname2' => array(
'frontend_label'=>'Apellido Materno',
'label' => 'Apellido Materno',
'input' => 'text',
'type' => 'varchar',
//System = False and visible true = Show in 'customer_account_create', 'customer_account_edit', 'checkout_register'
'system'=>true,
'visible'=>true, //Watch out!! Only visible fields get processed by the form controllers!!!
'user_defined'=>false,
'used_in_forms' => array('adminhtml_customer', 'customer_account_edit', 'checkout_register','customer_account_create'),
'required' => 0,
'position' =>69
));
foreach($attributes as $attribute_code=>$definition)
{
$installer->addAttribute('customer', $attribute_code, $definition);
/**
* #var Mage_Eav_Model_Config
*/
Mage::getSingleton('eav/config')
->getAttribute('customer', $attribute_code)
->setData('used_in_forms',$definition['used_in_forms'])
->save();
}
The code in name.phtml is
<div class="<?php echo $this->getContainerClassName()?>">
<?php if ($this->showPrefix()): ?>
<div class="field name-prefix">
<label for="<?php echo $this->getFieldId('prefix')?>"<?php if ($this->isPrefixRequired()) echo ' class="required"' ?>><?php if ($this->isPrefixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('prefix') ?></label>
<div class="input-box">
<?php if ($this->getPrefixOptions() === false): ?>
<input type="text" id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getPrefix()) ?>" title="<?php echo $this->getStoreLabel('prefix') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?> />
<?php else: ?>
<select id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" title="<?php echo $this->getStoreLabel('prefix') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?>>
<?php foreach ($this->getPrefixOptions() as $_option): ?>
<option value="<?php echo $_option?>"<?php if ($this->getObject()->getPrefix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div class="field name-firstname">
<label for="<?php echo $this->getFieldId('firstname')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('firstname') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('firstname')?>" name="<?php echo $this->getFieldName('firstname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php echo $this->getStoreLabel('firstname') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('firstname') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
<?php if ($this->showMiddlename()): ?>
<?php $isMiddlenameRequired = $this->isMiddlenameRequired(); ?>
<div class="field name-middlename">
<label for="<?php echo $this->getFieldId('middlename')?>"<?php echo $isMiddlenameRequired ? ' class="required"' : '' ?>><?php echo $isMiddlenameRequired ? '<em>*</em>' : '' ?><?php echo $this->getStoreLabel('middlename') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->escapeHtml($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('middlename') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
<?php endif; ?>
<div class="field name-lastname">
<label for="<?php echo $this->getFieldId('lastname')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('lastname') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo $this->getStoreLabel('lastname') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
<div class="field name-lastname">
<label for="<?php echo $this->getFieldId('lastname2')?>"><?php echo $this->getStoreLabel('lastname2') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('lastname2')?>" name="<?php echo $this->getFieldName('lastname2')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname2()) ?>" title="<?php echo $this->getStoreLabel('lastname2') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname2') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
<?php if ($this->showSuffix()): ?>
<div class="field name-suffix">
<label for="<?php echo $this->getFieldId('suffix')?>"<?php if ($this->isSuffixRequired()) echo ' class="required"' ?>><?php if ($this->isSuffixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('suffix') ?></label>
<div class="input-box">
<?php if ($this->getSuffixOptions() === false): ?>
<input type="text" id="<?php echo $this->getFieldId('suffix')?>" name="<?php echo $this->getFieldName('suffix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getSuffix()) ?>" title="<?php echo $this->getStoreLabel('suffix') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?> />
<?php else: ?>
<select id="<?php echo $this->getFieldId('suffix')?>" name="<?php echo $this->getFieldName('suffix')?>" title="<?php echo $this->getStoreLabel('suffix') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?>>
<?php foreach ($this->getSuffixOptions() as $_option): ?>
<option value="<?php echo $_option?>"<?php if ($this->getObject()->getSuffix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
This fields in the checkout you are talking about are address attributes, not customer attributes. So you need to load them differently. For registered users you could use Mage::getSingleton('customer/session')->getCustomer()->getLastname2() but it won't be saved to your address, as there is no attribute yet.
Depending on where you want lastname2 to be accessible you can create corresponding attributes for the entities customer_address,quote_address and order_address. They are created the same way you did for customer with
$installer->addAttribute($entityName, $attribute_code, $definition);
But that's not all. For the attributes to be converted correctly you need to set up conversion rules in your module config.xml. See for example the configuration of Mage_Sales.
In the global node there is a node fieldsets with the corresponding rules. There is a node customer_address to convert address attributes to quote address attributes. In sales_convert_quote there are rules to convert this attributes to order attributes.
So for your attributes to be accessible in all you config should look like this:
<global>
<fieldsets>
<customer_address>
<lastname2>
<to_quote_address>*</to_quote_address>
</lastname2>
</customer_address>
<sales_copy_order_billing_address>
<lastname2>
<to_order>*</to_order>
</lastname2>
<sales_copy_order_billing_address>
<sales_copy_order_shipping_address>
<lastname2>
<to_order>*</to_order>
</lastname2>
</sales_copy_order_shipping_address>
<sales_convert_quote_address>
<lastname2>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</lastname2>
</sales_convert_quote_address>
<sales_convert_order_address>
<lastname2>
<to_quote_address>*</to_quote_address>
</lastnam2e>
<sales_convert_order_address>
<customer_address>
<lastname2>
<to_quote_address>*</to_quote_address>
</lastname2>
</customer_address>
</fieldsets>
</global>
Related
I want to get the value clicked in radio button.
This is my code:
<ul class="collapsible popout" data-collapsible="accordion" id="clicks">
<?php
foreach ($preguntas['preguntas'] as $row)
{
$opciones = $pregunta->opciones($row[0]);
?>
<li>
<div class="collapsible-header"><i class="material-icons">question_answer</i><?php echo utf8_encode($row[2]); ?></div>
<div class="collapsible-body">
<?php foreach ($opciones as $opcion){ ?>
<p class="left-align" id="options">
<input class="with-gap" name="pregunta_<?php echo utf8_encode($row[0]); ?>" type="radio" id="opcion_<?php echo utf8_encode($opcion[0]); ?><?php echo $row[0] ?>" value="<?php echo $opcion[0]; ?>" />
<label for="opcion_<?php echo $opcion[0]; ?><?php echo utf8_encode($row[0]); ?>"><?php echo utf8_encode($opcion[2]); ?></label>
</p>
<?php } ?>
</div>
<?php } ?>
</li>
</ul>
I need to get the value of this input id="opcion_..."
<p class="left-align" id="options">
<input class="with-gap" name="pregunta_<?php echo utf8_encode($row[0]); ?>" type="radio" id="opcion_<?php echo utf8_encode($opcion[0]); ?><?php echo $row[0] ?>" value="<?php echo $opcion[0]; ?>" />
<label for="opcion_<?php echo $opcion[0]; ?><?php echo utf8_encode($row[0]); ?>"><?php echo utf8_encode($opcion[2]); ?></label>
</p>
The problem is name and id is changing, it's not the same
Any idea?
Thank you.
JQuery selector for part of attribute $("[attribute^='value']") like this:
$("[id^='opcion_']").click(function(){
alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label><input name="pregunta_xxx" type="radio" id="opcion_123" value="123">radio for 123</label>
<label><input name="pregunta_xxx" type="radio" id="opcion_456" value="456">radio for 456</label>
I have this code, which is very long, sorry.
<ul id="org" style="display:none">
<?php foreach ($note1 as $item1) { ?>
<li>
<?php echo $item1->Node_Id; ?>
<?php foreach ($noteLevel1 as $item2) { ?>
<p style="font-size:15px;padding:10px 5px 10px 0px"><?php echo $item2->LabelNote; ?></p>
<div class="SmallBox" id="<?php echo $item2->DetailNode_id; ?>" style="margin-bottom:10px;">
<input type="text" value="<?php if(empty($item2->Realisasi)) { echo ''; }else{ echo number_format($item2->Realisasi,0,",","."); } ?>" class="TextInput" />
<input type="text" value="<?php if(empty($item2->Target)) { echo ''; }else{ echo number_format($item2->Target,0,",","."); } ?>" class="TextInput" />
<input type="text" value="<?php if(!empty($item2->PercentRealisasi)) { echo $item2->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" />
<img class="circles4" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item2->PercentRealisasi; ?>);" />
</div >
<?php } ?>
<div class="clearDiv"></div>
<?php foreach ($note2 as $item3) { ?>
<?php echo $item3->Node_Id.'T'.$item3->ParentNode; ?>
<ul>
<?php foreach ($noteLevel2 as $item4) { ?>
<li>
<p class="NodeLabel"><?php echo $item4->LabelNote; ?></p>
<div id="<?php echo $item4->DetailNode_id; ?>" class="SmallBox">
<center>
<input type="text" value="<?php if(empty($item4->Realisasi)) { echo ''; }else{ echo number_format($item4->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(empty($item4->Target)) { echo ''; }else{ echo number_format($item4->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(!empty($item4->PercentRealisasi)) { echo $item4->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
<img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item4->PercentRealisasi; ?>);" />
</center>
</div>
<?php foreach ($note3 as $item5) { ?>
<?php echo $item5->Node_Id.'T'.$item5->ParentNode; ?>
<ul>
<?php foreach ($noteLevel3 as $item6) { ?>
<li>
<p class="NodeLabel"><?php echo $item6->LabelNote; ?></p>
<div id="<?php echo $item6->DetailNode_id; ?>" class="SmallBox">
<center>
<input type="text" value="<?php if(empty($item6->Realisasi)) { echo ''; }else{ echo number_format($item6->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(empty($item6->Target)) { echo ''; }else{ echo number_format($item6->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(!empty($item6->PercentRealisasi)) { echo $item6->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
<img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item6->PercentRealisasi; ?>);" />
</center>
</div>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
You can see the table in this picture:
The result should be like this:
I want node_id to appear when node_id is equal with parent_node. But when I try to add code like this:
<?php foreach ($note3 as $item5) { ?>
**<?php if($item5->ParentNode == $item3->Node_Id){ ?>**
<?php echo $item5->Node_Id.'T'.$item5->ParentNode; ?>
<ul>
<?php foreach ($noteLevel3 as $item6) { ?>
<li>
<p class="NodeLabel"><?php echo $item6->LabelNote; ?></p>
<div id="<?php echo $item6->DetailNode_id; ?>" class="SmallBox">
<center>
<input type="text" value="<?php if(empty($item6->Realisasi)) { echo ''; }else{ echo number_format($item6->Realisasi,0,",",".");} ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(empty($item6->Target)) { echo ''; }else{ echo number_format($item6->Target,0,",","."); } ?>" class="TextInput" readonly="true"/>
<input type="text" value="<?php if(!empty($item6->PercentRealisasi)) { echo $item6->PercentRealisasi.'%'; }else{ echo '0%'; } ?>" class="PercentInput" readonly="true"/>
<img class="circles" src='http://localhost/CST/public/img/green.png' onload="this.onload=null; this.src=GetStatusImage(<?php echo $item6->PercentRealisasi; ?>);" />
</center>
</div>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
And the result should be like this:
It's like I just loop with the first index of the array. How can I fix it?
I have a magento store where the Add to Cart button has stopped working and instead a search query is performed ( where the & are changed to & so it doesn't even work ) This can be seen by adding a item to cart here: http://bit.ly/1o8SwmE
This add to cart button does however work on category grid pages. I have tried pasting the link generated in the form into a web browser and it also redirects me to the same broken search page, I have also tried pasting the action link from the add to cart form on a working category grid page into firebug on the non working page and this then adds the product from the category page perfectly.
The snippets of code i have used are pasted below and other people have had them working it seems so this may not be the issue.
OLD CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('QTY') ?>:</label>
<input type="text" name="qty" id="qty" class="new-qty-cat" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button class="new-qty-button" type="button" onclick="this.form.submit()"></button>
</form>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
NEW CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
<button class=form-button" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()"><span><?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript"> var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_<?php echo $_product->getId(); ?>'); productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){ if (this.validator.validate()) { this.form.submit(); } }.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);</script>
NEW CODE 2
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
New Code 3
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input class="new-qty-cat" type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" class="new-qty-button" onclick="this.form.submit()"><span><span> </span></span></button>
</form>
I'm having a problem with my custom Wordpress Widget I'm making. For some weird reason the form function gets ran twice, and thus, makes two Redactor textareas, but it only happends when I add the widget to a sidebar. Not when I click the save button after it has been added.
How can I do so my form function only gets ran once, or at least make the JavaScript run once.
Full widget code
http://pastebin.com/BHDJSxWX
My form function
function form($instance)
{
$instance = wp_parse_args((array) $instance, array( 'box1' => '', 'box2' => '', 'box3' => '', 'box4' => '' ));
$box1 = $instance['box1'];
$box2 = $instance['box2'];
$box3 = $instance['box3'];
$box4 = $instance['box4'];
$boxqty = $instance['boxqty'];
$uniqueID = rand();
echo "Unique ID: ".$uniqueID;
?>
<p>
<label for="<?php echo $this->get_field_id('boxqty'); ?>">Number of blocks: (1-4)
<input class="widefat" id="<?php echo $this->get_field_id('boxqty'); ?>" name="<?php echo $this->get_field_name('boxqty'); ?>" type="text" value="<?php echo attribute_escape($boxqty); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('box1'); ?>">Box 1:
<textarea class="widefat redactor_content_<?php echo $uniqueID; ?>" id="box1" name="<?php echo $this->get_field_name('box1'); ?>" style="width: 600px;"><?php echo $box1; ?></textarea>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('box2'); ?>">Box 2:
<textarea class="widefat redactor_content_<?php echo $uniqueID; ?>" id="<?php echo $this->get_field_id('box2'); ?>" name="<?php echo $this->get_field_name('box2'); ?>" style="width: 600px;"><?php echo $box2; ?></textarea>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('box3'); ?>">Box 3:
<textarea class="widefat redactor_content_<?php echo $uniqueID; ?>" id="<?php echo $this->get_field_id('box3'); ?>" name="<?php echo $this->get_field_name('box3'); ?>" style="width: 600px;"><?php echo $box3; ?></textarea>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('box4'); ?>">Box 4:
<textarea class="widefat redactor_content_<?php echo $uniqueID; ?>" id="<?php echo $this->get_field_id('box4'); ?>" name="<?php echo $this->get_field_name('box4'); ?>" style="width: 600px;"><?php echo $box4; ?></textarea>
</label>
</p>
<!--Activate Redactor-->
<script type="text/javascript">
jQuery('.redactor_content_<?php echo $uniqueID; ?>').redactor({
fixed: true
});
console.log('Unique ID: <?php echo $uniqueID; ?>');
</script>
<?php
}
I tested some things and what seems to be happening is that the whole widget loads both on the left, where the widget form content is hidden, and on the right in the 'active' widgets sections. Untested, but you should be able to target the 'active' section only with:
jQuery('.widgets-holder-wrap .redactor_content_<?php echo $uniqueID; ?>').redactor({
fixed: true
});
If I had the complete widget I might be able to spot something else.
i am populating a form from mysql. code is. .
task.php
<div data-role="content">
<h2> Please select cars </h2>
<form method="post" action="cars.php">
<?php
$carq = "select * from cars";
$executecars = mysql_query($carq);
while($row=mysql_fetch_assoc($executecars)){
$cname = $row['name'];
?>
<label for="<?php echo $cname; ?>"><?php echo $cname; ?></label>
<input type="checkbox" name="car" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>
<?php }
?>
<input type="submit" name="submitcars" id="submitcars" value="View Details"/>
</form>
</div>
now in cars.php i want to make a query to display the details of car selected,
<div data-role="content">
<?php
if(isset($_POST['submitcars'])){
echo $_POST[$cname];?????????????
}
?>
</div>
now how to process the form here in cars.php ?
thanks
Make car attribute array::
<input type="checkbox" name="car[]" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>
and get them on next page with
if(isset($_POST['submitcars'])){
foreach($_POST['car'] as $car){
// do something with $car
}
}
Try this
<form method="post" action="cars.php">
<?php
$carq = "select * from cars";
$executecars = mysql_query($carq);
while($row=mysql_fetch_assoc($executecars)){
$cname = $row['name'];
?>
<label for="<?php echo $cname; ?>"><?php echo $cname; ?></label>
<input type="checkbox" name="car[]" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>
<?php }
?>
Firstly, let me preface this by saying that you shouldn't be using the mysql functions. They're depreciated and no longer recommended.
On task.php, your opening form tag was being printed inside your loop. Secondly, you should probably use an array of checkboxes using [].
<div data-role="content">
<h2> Please select cars </h2>
<form method="post" action="cars.php">
<?php
$carq = "select * from cars";
$executecars = mysql_query($carq);
while($row=mysql_fetch_assoc($executecars)){
$cname = $row['name'];
?>
<label for="<?php echo $cname; ?>"><?php echo $cname; ?></label>
<input type="checkbox" name="cars[]" id="<?php echo $cname; ?>" value="<?php echo $cname; ?>"/>
<?php } ?>
<input type="submit" name="submitcars" id="submitcars" value="View Details"/>
</form>
</div>
Then, on cars.php:
<div data-role="content">
<?php
if(isset($_POST['submitcars'])){
if(isset($_POST['cars'] && count($_POST['cars']) > 0){
foreach($_POST['cars'] as $key => $car){
echo $car . '<br /'>;
}
}
else{
echo 'No cars found!';
}
}
?>
</div>