Objective:
list a set of records with a checkbox next to each along with a "delete" input. If the user checks one checkbox or multiple checkboxes, the submit action will get the id of each checkbox and delete corresponding record(s).
I know this functionality is provided on the backend, but I'm trying provide the functionality to the frontend users that are logged in.
Update: I can now render the widget correctly, but am still having difficulty capturing the ID of the checkbox(s) that are selected. Help here would be appreciated.
Index page:
<h1>Jobs</h1>
<?php include_partial('list', array('saved_jobss' => $saved_jobss, 'form' => $form)) ?>
//I'm not sure if I can even pass two objects??
Index action:
public function executeIndex(sfWebRequest $request)
{
$userId = sfContext::getInstance()->getUser()->getId();
$this->saved_jobss = Doctrine_Core::getTable('saved_jobs')->getSavedJobs($userId);
$this->form = new Saved_JobsForm();
}
Partial page named: _list
<table class="sortable">
<thead>
<tr>
<th>Delete</th>
<th>Company:</th>
<th>Job name:</th>
<th>Job No.</th>
<th>Saved:</th>
</tr>
</thead>
<tbody>
<?php foreach ($saved_jobss as $saved_jobs): ?>
<tr>
<td>
<?php echo $form['id']->renderRow() ?>
<td>
<a href="
<?php
$jobId = $saved_jobs->getJobId();
echo 'job/'.$saved_jobs->getJob($jobId);
?>
">
<?php
$jobId = $saved_jobs->getJobId();
echo $saved_jobs->getJobCompany($jobId);
?>
</a>
</td>
<td>
<?php
$jobId = $saved_jobs->getJobId();
echo $saved_jobs->getJobName($jobId);
?>
</td>
<td>
<?php
echo $saved_jobs->getJobId();
?>
</td>
<td><?php echo date("M-j-y", strtotime($saved_jobs->getCreatedAt())) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="submit" value="Delete" />
</form>
Action:
public function executeSubmit(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod('post'));
$params = $request->getPostParameters();
$this->redirect('saved_jobs/deleteConfirmation?'.http_build_query($params));
}
Form class:
class Saved_JobsForm extends BaseSaved_JobsForm
{
public function configure()
{
$this->widgetSchema['id'] = new sfWidgetFormInputCheckbox();
$this->widgetSchema->setLabel('id', false);
}
}
I tinkered with the idea of using javascript, but was unsure if that was the way to go or not. Any help, or a point in the right direction would be most appreciated. Thanks in advance.
Solved: I just passed a link to each record with the action and record Id.
Related
I'm having issues on my WordPress page getting tablesorter to sort the data when the page initially loads. When the page initially loads it sorts the table by post date. Any way I can get it sorted by date_signed in descending order when the page loads initially? I can click the sort button on the table after the page has loaded and it sorts just fine, so its working, its just ignoring the initial sort function. I'm not a strong coder, so I appreciate the help. I'm working with existing code.
Thanks!
<?php /* Template Name: All Court Orders */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'header' ); ?>
<?php // Get all amendments
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'court_order',
'meta_key' => 'date_signed',
'orderby' => 'meta_value_num',
'order' => 'DESC'
)); ?>
<div class="row">
<div class="col-md-12">
<div class="table-responsive" id="tblOpinions">
<table class="table table-striped tablesorter" id="myTable">
<thead>
<tr>
<th>Order Name</th>
<th>Date Signed</th>
<th>Effective Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($posts as $post) { ?>
<?php
$file = get_field('file_upload');
$dateSigned = get_field('date_signed', false, false);
$dateSigned = new DateTime($dateSigned);
$dateEffective = get_field('effective_date', false, false);
$dateEffective = new DateTime($dateEffective);
$name = get_the_title();
?>
<tr>
<td><?php the_title(); ?></td>
<td><?php echo $dateSigned->format('m/d/Y'); ?></td>
<td><?php echo $dateEffective->format('m/d/Y') ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer(); ?>
<script>
$(document).ready(function()
{
$("#myTable").tablesorter( {
sortList: [[1,1]]
});
}
);
</script>
how do i generate only 3 columns in a page using below code
if i keep echo'(table)' inside it generates the whole table so i want only one table
allow only 3 columns in a page after 3 columns append a new row
<?php
$i = 0;
echo '<table style="float: left;width: -weekbit-fill-available"; ><tr>';
?>
<?php foreach ($product as $p) {
$i++;
// $i++;
echo "<tr><td>Name:<b>". $p->name ."</td></tr>";
echo "<tr><td>productID:<b>".$p->proid ."</td></tr>";
echo "<tr><td>Price:<b>". $p->price ."</td></tr>";
echo "<tr><td><a href='/cart/cart/add?id=$p->proid'><input type='button' value='addtocart'/></td></tr>";
if($i==3){
echo '</tr><tr>';
}
echo"</tr>
</table>";
?>
<?php }?>
<?php echo"</tr>
</table>"?>
thanks in advance
Try below
<table style="float: left; width: -weekbit-fill-available">
<tr>
<th>Name</th>
<th>ProductID</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php foreach ($product as $p) : ?>
<tr>
<td><?= $p->name ?></td>
<td><?= $p->proid ?></td>
<td><?= $p->price ?></td>
<td colspan="3"><?= \yii\helpers\Html::a('addtocart',
['/cart/cart/add', 'id' => $p->proid],
[
'title' => 'Add to Cart',
'class' => 'btn btn-warning btn-sm',
]); ?></td>
</tr>
<?php endforeach; ?>
</table>
Use <tr> for each row and <td> for each column
<table style="float: left; width: -weekbit-fill-available"; >
<?php foreach ($product as $p): ?>
<tr>
<td>Name: <b><?= $p->name ?></td>
<td>productID: <b><?= $p->proid ?></td>
<td>Price: <b><?= $p->price ?></td>
<td><a href='/cart/cart/add?id=<?= $p->proid ?>'><input type='button' value='addtocart'/></td>
</tr>
<?php endforeach; ?>
</table>";
See also:
HTML tables https://www.w3schools.com/html/html_tables.asp
Yii2 GridView https://www.yiiframework.com/doc/guide/2.0/en/output-data-widgets
I am joining two tables (companies and users on users.id=companies.user_id), send the data to the controller and then pass it to the view where it tells me that $id is an undefined property referring to the line in the view where it says ($comps->id).
Without a join, this message does not show up and all is fine. Do I have to access the properties differently when having a join?
Model:
public static function companyUser(){
return DB::table('companies as c')
->leftJoin('users', 'c.user_id', '=', 'users.id')
->select('users.user_name as uname, c.*')
->get();
}
Controller:
$data['companies'] = Companies::companyUser();
return View::make('admin/companies_view', $data);
View:
<?php if($companies) : ?>
<?php foreach($companies as $comps) : ?>
<tr>
<td class="center"><?php echo $comps->id; ?></td>
<td><?php echo $comps->company; ?></td>
<td class="center"><?php echo $comps->uname; ?></td>
<td class="center"><?php echo $comps->rate; ?></td>
<td class="center"><?php echo $comps->status; ?></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="8" class="no_results">There are no Users</td>
</tr>
<?php endif; ?>
I think the error is probably that select() expects each thing you want to get as a separate string. So if you want both the user_name and c.*, you'll need to do this:
->select('users.user_name as uname', 'c.*')
That should hopefully be enough to get it going. :)
Ok, I have index.html with a form as follows:
<form action="process.php" method="post">
<table>
<tr>
<td><input name="Field[]" type="checkbox" value="Accounting" />Accounting</td>
<td><input name="Field[]" type="checkbox" value="Finance" />Finance</td>
<td><input name="Field[]" type="checkbox" value="Marketing" />Marketing</td>
</tr>
</table>
</form>
And I have process.php as follows:
<table>
<tr>
<th>Field(s):</th>
<td>
<?php
if(isset($_POST['Field']))
{
for($i = 0; $i < count($_POST['Field']); $i++)
{ echo $_POST['Field'][$i] . ' '; }
}
?>
</td>
</tr>
</table>
Yet for some reason, I only get the first letter of the last checkbox that was checked printed out. Help please!
Try this one in process.php to get the values from $_POST['Field']
<table>
<tr>
<th>Field(s):</th>
<td>
<?php
if(isset($_POST['Field']))
{
foreach ($_POST['Field'] as $value) {
echo $value;
}
}
?>
</td>
</tr>
</table>
I have an embeddedForm that I am trying to configure the widgets for.
Currently I am just outputting the form in a _form.php template like:
<?php echo $form ?>
This is great, but I'd like to have my form fields in a particular order, so I thought I'd try:
<?php echo $form['firstname']->renderRow() ?>
<?php echo $form['lastname']->renderRow() ?>
<?php echo $form['email_address']->renderRow() ?>
This gives me an invalid widget error.
Now I have 2 forms, one is a basic form, that simply embeds another form.
<?php
class labSupportForm extends sfGuardUserAdminForm
{
public function configure()
{
$form = new labSupportProfileForm($this->getObject()->getProfile());
$this->embedForm('profile', $form);
unset($this['is_super_admin'], $this['is_admin'], $this['permissions_list'], $this['groups_list']);
$this->widgetSchema['profile'] = $form->getWidgetSchema();
$this->validatorSchema['profile'] = $form->getValidatorSchema();
}
public function save($con = null)
{
$user = parent::save($con);
if (!$user->hasGroup('Lab Support'))
{
$user->addGroupByName('Lab Support');
$user->save();
}
return $user;
}
}
and:
<?php
class labSupportProfileForm extends sfGuardUserProfileForm
{
public function configure()
{
unset($this['email_new'],
$this['validate_at'],
$this['validate'],
$this['address_1'],
$this['address_2'],
$this['city'],
$this['country'],
$this['postcode'],
$this['created_at'],
$this['updated_at'],
$this['user_id'],
$this['is_super_admin'],
$this['is_admin'],
$this['permissions_list'],
$this['groups_list']);
}
}
But If I add the widget/validator to the labSupportForm and save, the firstname value doesn't save.
Am I doing something wrong here, as I would have thought this value would save.
Thanks
When you render a form by fields, you have to explicitly call $form->renderHiddenFields(). For example:
<?php echo form_tag_for($form, '#url') ?>
<table>
<tfoot>
<tr>
<td colspan="2">
<input type="submit" value="Save" />
<?php echo $form->renderHiddenFields() ?>
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form['username']->renderRow() ?>
<?php echo $form['profile_form']->renderRow() ?>
</tbody>
</table>
</form>
Also, beware calling embedded form name the same as relation name (e.g. 'profile') or you will have troubles when saving it. Just add '_form' suffix and you will be safe:
$this->embedForm('profile_form', $form);
If you want to keep a linear display structure of your form fields, you should render them explicitly according to your widget schema:
<?php echo $form['username']->renderRow() ?>
<?php echo $form['profile_form']['first_name']->renderRow() ?>
<?php echo $form['profile_form']['last_name']->renderRow() ?>
Or you can do it automatically for all fields of an embedded form:
<?php foreach ($form['profile_form'] as $field): ?>
<?php if (!$field->isHidden()): ?>
<?php echo $field->renderRow() ?>
<?php endif; ?>
<?php endforeach; ?>
Call $this->saveEmbeddedForms() in the labSupportForm save method