In codeigniter currently I am working on shopping cart but the problem is I am not able to call a function using form_open in codeigniter.
However, in the same project in another place same code is working properly but in other view form_open it's not working.
Here is my code:
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',['class'=>'form-horizontal']);?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',['class'=>'btn btn-primary'])?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
<?php echo form_close(); ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>
check to see if you are loading the helper.
$this->load->helper('form');
somewhere in your code. preferably in the constructor.
also make sure that error notifications are are turned on, these sorts of problems should give errors that help.
change your code with below one
<?php if(count($data)):?>
<?php foreach($data as $head_data) :?>
<div class="row">
<?php echo form_open('Shopingcart/add',array('class'=>'form-horizontal'));?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="imagebox">
<img src=<?php echo base_url($head_data->p_image)?> class="" alt="picture">
<h2>New This Week</h2>
<p>Browse New Portraits and Abstracts</p>
<p id="id"><?= $head_data->p_id ?></p>
<p id="p_price"><?= $head_data->p_price ?></p>
<p id="p_name"><?= $head_data->p_name ?></p>
<?= anchor('Stuff','View Collections',array('class'=>'btn btn-primary'))?>
<?php
echo form_hidden('id', $head_data->p_id);
echo form_hidden('qty', 1);
echo form_hidden('name', $head_data->p_name);
echo form_hidden('price', $head_data->p_price);
?>
<p><?php echo form_submit('', 'Add to Cart'); ?></p>
</div>
</div>
<?php echo form_close(); ?>
<?php endforeach; ?>
<?php else: ?>
<p> No content found</p>
<?php endif ?>
Related
I have a repeater inside a repeater and I need to loop what is in it.
I'm following this: https://www.advancedcustomfields.com/resources/have_rows/
This is my field structure:
agenda_section_events (parent/repeater)
agenda_event_time_pacific (text)
agenda_event_time_eastern (text)
agenda_event_title (text)
agenda_event_speakers (repeater)
agenda_event_speaker_headashot (image array)
agenda_event_speaker_name (text)
agenda_event_speaker_title (text)
agenda_event_speaker_content (wysiwyg editor)
So with that in mind, as I understand it, I need to loop over agenda_section_events and inside that I need to get rows https://www.advancedcustomfields.com/resources/have_rows/
So that code looks like this:
<div class="tc__agenda-items">
<?php foreach($agendaSectionEvents as $agendaSectionEvent): ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php echo have_rows('agenda_event_speakers') ?></div>
<?php if(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker">
<?php while(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endforeach ?>
</div>
I'm really confused because all my field names are right, and the fields inside the second loop are sub fields but nothing is showing.
Why would that be?
I then thought its because I did a have rows inside a for each so then I tried doing a while inside a while like the acf docs
<div class="tc__agenda-items">
<?php while(have_rows('agenda_section_events')): ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php echo have_rows('agenda_event_speakers') ?></div>
<?php if(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker">
<?php while(have_rows('agenda_event_speakers')): ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endwhile ?>
</div>
<?php endif ?>
Since implementing this change, now the page just...doesn't load!? What!?
How do you do a nested for loop in advanced custom fields?
You need to add the_row(); inside your while loops. All ACF loops are formatted the same, nested or not. Something I do to keep it easy is make the if/while/the_row stuff all one line, see below:
Start loops like this:
<?php if (have_rows('agenda_section_events')): while (have_rows('agenda_section_events')) : the_row(); ?>
End loops like this:
<?php endwhile; endif; ?>
You can go wild with the number of loops you want to nest, just simply copy the parent loop lines and create a nested one, then change your row to the nested one of course.
I adjusted your code below, give this a shot.
You should also define your subfield array values inside the loop you're using it with, just keeps things cleaner – or just use the_sub_field to echo your subfield values since its a short function anyway.
<div class="tc__agenda-items">
<?php if (have_rows('agenda_section_events')): ?>
<?php while (have_rows('agenda_section_events')) : the_row(); ?>
<div class="tc__agenda-item">
<div class="tc__agenda-time">
<div class="tc__agenda-time--pacific">
<?php echo $agendaSectionEvent['agenda_event_time_pacific'] ?>
</div>
<div class="tc__agenda-time--eastern">
<?php echo $agendaSectionEvent['agenda_event_time_eastern'] ?>
</div>
</div>
<h3><?php echo $agendaSectionEvent['agenda_event_title'] ?></h3>
<div class="tc__agenda-speaker-list">
<!-- DEBUG LINE - BUT ITS EMPTY -->
<div style="color: red;"><?php // echo have_rows('agenda_event_speakers') ?></div>
<?php if (have_rows('agenda_event_speakers')) ?>
<div class="tc__agenda-speaker">
<?php while (have_rows('agenda_event_speakers')) : the_row(); ?>
<div class="tc__agenda-speaker-headshot">
<img src="<?php the_sub_field('agenda_event_speaker_headashot')['url'] ?>" alt="<?php the_sub_field('agenda_event_speaker_headashot')['alt'] ?>">
</div>
<div class="tc__agenda-speaker-info">
<h4><?php the_sub_field('agenda_event_speaker_name') ?></h4>
<p><?php the_sub_field('agenda_event_speaker_title') ?></p>
</div>
<?php endwhile ?>
</div>
<?php endif ?>
</div>
Learn More
</div>
<?php endwhile ?>
<?php endif ?>
I am trying to make image as a link in Codeigniter but <a> tag is not working. I am trying to make image as a link but inside foreach loop <a> tag is not working.
Here is my code
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<a href=<?php echo site_url($post->url)?>> <img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
</div>
</div>
change your code to this and please check again.
<?php if(count($trendpost)):?>
<?php if(count($trendpost)<=3):?>
<div class="row">
<?php foreach($trendpost as $post): ?>
<div class="col-lg-4 col-md-4">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="row">
<?php foreach($trendpost as $post) :?>
<div class="col-lg-4 col-md-4">
<a href="<?php echo site_url($post->url)?>" style="display: block;">
<img class="imageborder trendimg" src=<?php echo site_url($post->link)?>></a>
<p><?= $post->news ?></p>
</div>
<?php endforeach; ?>
</div>
<?php endif ?>
<?php else: ?>
<p> not found</p>
<?php endif ?>
You can use
<?php echo anchor('your Controller_name/link','<img src="your path" /> ','class="btn btn-default btn-flat"')?>
instead of anchor Tag
i have installed magento 1.8.1 and i want to show My Cart right after banner section. i am placing the code in banner.phtml file and it seems working but problem is that it is not showing cart items and cost etc stuff.
can any one please share some universal code that can be used anywhere in .phtml file.
my source code is below:
<div class="slider-mycart">
<div class="block block-verticalmenu">
<div>
<div class="block-cart">
<?php $_cartQty = $this->getSummaryCount() ?>
<!--<span class="top-cart-icon"></span>-->
<span>
<!--<span>Shopping Cart</span><br/>-->
<?php echo $this->__('My Cart') ?>: <?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?></span>
<div class="top-cart-content">
<?php $_items = $this->getRecentItems() ?>
<?php if(count($_items)): ?>
<ol id="cart-sidebar" class="mini-products-list">
<?php foreach($_items as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script>
<?php else: ?>
<p class="empty"><?php echo $this->__('You have no items in your shopping cart.') ?></p>
<?php endif ?>
<?php if($_cartQty && $this->isPossibleOnepageCheckout()): ?>
<div class="actions">
<?php echo $this->getChildHtml('extra_actions') ?>
<button type="button" title="<?php echo $this->__('Checkout') ?>" class="button" onclick="setLocation('<?php echo $this->getCheckoutUrl() ?>')"><span><span><?php echo $this->__('Checkout') ?></span></span></button>
</div>
<?php endif ?>
</div>
</div>
</div>
</div>
</div>
The structure of the main body of my page is constructed of three columns, these columns are generated by MYSQL data and then formulated in to three columns using PHP.
Below is PHP code and the layout which provides the three columns. The problem which I have is that if the data provides a layout two columns wide then everything is fine and it looks like this.
http://goo.gl/TDKI2J
However if the data provides a layout three columns wide then it looks like this.
http://goo.gl/0uqPvX
I think the problem is the div tag after the on the third column, but not sure of the best way to fix the issue.
Here is the code.
<?php $columnSelector = 0; // define a column selector ?>
<?php while($row = mysql_fetch_array($result)) :?>
<?php if ($columnSelector == 0): ?>
<div class="row-fluid">
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> | </p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
<?php elseif ($columnSelector == 1): ?>
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image_link']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> <?php echo $row['date']; ?> | <?php echo $row['posted_by']; ?></p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
<?php elseif ($columnSelector == 2): ?>
<article class="span4 mid">
<div class="img">
<img src="images/<?php echo $row['image_link']; ?>" alt="post4" />
<div class="overlay"></div>
</div>
<div class="info">
<p class="tags">
<?php echo $row['event_type']; ?>
<?php echo $row['location']; ?>
</p>
<h1><?php echo $row['event_title']; ?></h1>
<p class="details"> <?php echo $row['date']; ?> | <?php echo $row['posted_by']; ?></p>
<p class="text">
<?php echo $row['event_details_short']; ?>
</p>
</div>
</article>
</div>
<?php endif; ?>
<?php $columnSelector++; // advance to the next row?>
<?php $columnSelector %= 3; // reset to zero every third event?>
<?php endwhile; ?>
It is probably the if statement don't let the code below to shown.
This line : <?php if ($columnSelector == 0): ?>
OK, solved it, the problem was the last tag here:
</article>
</div>
It was needed for when only one or two columns show but not for the third and so i replaced it with this.
</div>
</article>
<?php if ($columnSelector == 1){ ?>
</div>
<?php } ?>
<?php endif; ?>
And so now when there is three columns the div doesn't show and the layout is correct.
I am using radio buttons in Yii and no matter what I do I can't get the value of the selected button to post. I am sure its just something simple. I am NOT using radioButtonList because I want each button to exist in its own div with an image above it.
Here is my code from the view...
<?php $this->pageTitle=Yii::app()->name; ?>
<h1>Welcome to <i><?php echo CHtml::encode(Yii::app()->name); ?></i></h1>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'lead_form',
'enableAjaxValidation'=>false,
)); ?>
<h3>Choose Your Prize!</h3>
<div id="prizes">
<div class="prize">
<h3>Paypal</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>1)); ?>
</div>
<div class="prize">
<h3>Check</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>2)); ?>
</div>
<div class="prize">
<h3>AlertPay</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>3)); ?>
</div>
<div class="prize">
<h3>Iphone 4</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>4)); ?>
</div>
<div class="prize">
<h3>Ipad 2</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>5)); ?>
</div>
<div class="prize">
<h3>Custom</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>6)); ?>
</div>
</div>
<h3>Enter Your Email</h3>
<div id="mainemail">
<div class="row">
<?php echo $form->labelEx($model,'user_email'); ?>
<?php echo $form->textField($model,'user_emhttp://stackoverflow.com/editing- helpail'); ?>
<?php echo $form->error($model,'user_email'); ?>
</div>
<div>
<?php echo $form->errorSummary($model); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
endWidget(); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>1,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>2,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>3,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>4,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>5,'uncheckValue'=>null)); ?>
just add
'uncheckValue'=>null
in htmlOption array
it will work..
In CHtml::activeRadioButtonList's third parameter (htmlOptions) there is an option called 'template'. You should take a look.