Yii form fields rendered twice - php

The fields of my yii form in the register page are rendered twice!!
can anybody pls help me find out what's causing this?
here is the code from the controller:
public function actionRegister()
{
$form=new Users;
// collect user input data
if(isset($_POST['Users']))
{
$form->attributes=$_POST['Users']; // set all attributes with post
// NOTE Changes to any $form->value have to be performed BEFORE $form-validate()
// or else it won't save to the database.
// validate user input and redirect to previous page if valid
if($form->validate())
{
// save user registration
$form->save();
$this->redirect(Yii::app()->createUrl('site/login'));
}
}
// display the registration form
$this->render('register',array('form'=>$form));
}
here is the code from the view:
<?php $pagetitle = "Hubylon | Register"; ?>
<?php $this->breadcrumbs=array('Register'); ?>
<div class="yiiForm">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($form); ?>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'username'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'username'); ?></td>
<td><?php echo CHtml::error($form,'username',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'password'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'password'); ?></td>
<td><?php echo CHtml::error($form,'password',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'confirmPassword'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'confirmPassword'); ?></td>
<td><?php echo CHtml::error($form,'confirmPassword',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'first_name'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'first_name'); ?></td>
<td><?php echo CHtml::error($form,'first_name',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'birthdate'); ?>:</td>
<td><?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'attribute'=>'birthdate',
'model' => $form,
//'language'=>Yii::app()->language=='en' ? 'en' : null,
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'defaultDate'=>$form->birthdate,
'buttonImage'=>Yii::app()->baseUrl.'/images/icons.date.png',
'buttomImageOnly'=>true,
'showAnim'=>'fold',
'showOn'=>'button',
'yearRange'=>'1900',),
'htmlOptions'=>array(
'style'=>'width:80px;vertical-align:top'
),
));
?></td>
</tr>
</table>
</div>
<div class="action">
<?php echo CHtml::submitButton('Register'); ?>
</div>
<?php echo CHtml::endForm(); ?>
thanks!

seems there's no problem from the code you have given,
but maybe you can checkout the layouts and the init() method of the current controller.

i managed to resolve it by adding the following line before the render:
$this->layout = '//layouts/login';
thanks!

Related

Php mysqli list result's except those with *

I have this list, but i want my own IP adres to not show in this list,
how can i make an exception? like , if (Myip = in there) { dont show}
<?php
session_start();
include_once 'dbconnect.php';
?>
<?php include ('head.php') ; ?>
<?php include ('menu.php') ; ?>
<?php if (isset($_SESSION['usr_id'])) { ?>
<?
$user_list_result = $DBcon->query("select * from users order by username ASC limit 100");
$loggedTime=strtotime('-600 seconds'); //2 minutes
$session = $_SESSION['usr_name'];
$query = $DBcon->query("SELECT * FROM users WHERE username='$session'");
$userRow=$query->fetch_array();
if ($userRow['userlevel'] > 254) {
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-9 well">
<div class="panel panel-default panel-compact panel-wallet">
<div class="panel-body">
<center><h1>Userlist</h1></center>
<center>
<table >
<tr> <td width="20%"><b>ID </b></td>
<td width="20%"><b>Nickname </b></td>
<td width="20%"><b>Email </b></td>
<td width="20%"><b>Status </b></td>
<td width="20%"><b>Message </b></td>
<td width="20%"><b>Click </b></td>
<td width="20%"><b>clicks </b></td>
<td width="20%"><b>credits </b></td>
<td width="20%"><b>bitcoins </b></td>
<td width="20%"><b>dogecoins </b></td>
<td width="20%"><b>dashcoins </b></td>
<td width="20%"><b>refferals </b></td>
<td width="20%"><b>ip </b></td>
<td width="20%"><b>password </b></td>
<td width="20%"><b>edit </b></td> </tr>
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php } ?> </table>
</center>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } else { include('login.php'); } ?>
<?php include ('footer.php') ; ?>
If you have a static ip then you can add a condition in the while loop as soon as it starts like,
if($ip_variable == "YOUR_IP"){
continue;
}
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
if($UserlistRow[ip]!="ENTER YOUR IP HERE")
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php }
}?>

Diffrent query in one function codeigniter

I use Codeigneter and I make a search function and in my function I want run two diffrent query and I want show them in diffrent table, How I can do that Sorry I can't show the data
This is My code:
My controller
function showDetail(){
// Retrieve the posted search term.
$detailTiket = $this->input->get('ticket_id');
// Use a model to retrieve the results.
$data["result"]= $this->tracking_model->showDetail($detailTiket);
$data1["result"]= $this->tracking_model->showDetail2($detailTiket);
// Pass the results to the view.
$this->load->view('tracking/tiket_detail',$data,$data1);
}
My Model
function showDetail($detailTiket)
{
if($detailTiket==""){
$detailTiket = "";
}
$showDetailTiket=$this->db->query("My Query1");
return $detailTiketDown->result();
}
function showDetail2($detailTiket)
{
if($detailTiket==""){
$detailTiket = "";
}
$detailTiketDown=$this->db->query("My query2");
return $detailTiketDown->result();
}
My view
<table Width='800'>
<?php
foreach($data as $row){?>
<tbody>
<tr>
<td><?php echo $row->ticket_id; ?></td>
</tr>
<tr>
<td><?php echo $row->created_time; ?></td>
</tr>
<tr>
<td><?php echo $row->start_IT; ?></td>
</tr>
<tr>
<td><?php echo $row->estimasi_selesai; ?></td>
</tr>
<tr>
<td><?php echo $row->name; ?></td>
</tr>
<tr>
<td><?php echo $row->description; ?></td>
</tr>
<tr style="background-color: cyan">
<td><b><?php echo $row->Status; ?></b></td>
</tr>
</tbody>
<?php } ?>
</table>
</center>
</div>
<div>
<table Width='1000'>
<?php foreach($data1 as $rows){ ?>
<tbody>
<tr>
<td><?php echo $rows->Tgl_Waktu; ?></td>
<td><?php echo $rows->PIC; ?></td>
<td><?php echo $rows->Tracking_Ticket; ?></td>
<td><?php echo $rows->Keterangan_Ticket; ?></td>
<td><?php echo $rows->File_Pendukung; ?></td>
</tr>
</tbody>
<?php }?>
</table>
You can pass data like Associative array to view
change your controller like this
Controller:
$data["result"]= $this->tracking_model->showDetail($detailTiket);
$data["result1"]= $this->tracking_model->showDetail2($detailTiket);
// Pass the results to the view.
$this->load->view('tracking/tiket_detail',$data);
view:
Table1 :
foreach($result as $row)
{
//for first result
}
Table2:
foreach($result1 as $row1)
{
//for second result
}

Can't put data from database to a table with PHP

My problem is that I can't fill my table with the data I got in my database. I wrote a code in PHP to do it but it doesn't work and I don't know how to make it work. Any idea ? Here's my code :
view gestJury :
<h3>Liste des jurys :</h3>
<div class="tablebox">
<table>
<thead>
<tr>
<th>N°</th>
<th>Professeur1</th>
<th>Professeur2</th>
<th>Salle</th>
<th>Heure</th>
<?php if($rang == 0){ ?>
<th class="action" >Supprimer</th>
<?php } ?>
</tr>
</thead>
<?php $i = 0; ?>
<?php while($donnees = $listeJury->fetch(PDO::FETCH_ASSOC)){
$i = $i + 1;
?>
<tbody>
<tr class="row0">
<td><?php echo $donnees['idJury'] ?></td>
<td><?php echo $donnees['idProf'] ?></td>
<td><?php echo $donnees['idProf2'] ?></td>
<td><?php echo $donnees['Salle'] ?></td>
<td><?php echo $donnees['horaireJury'] ?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
index.php :
function listJuryGlobal(){
$jury = new Professeur();
$listeJury = $jury->getJuryGlobal();
require('view/gestJury.php');
}

Multiple SELECT variables are not displaying

Having issues displaying all of the selected data entries inside SELECT. Right now the only one that is displaying is the recipe_direct data. Each table data should list in one row the name, ingred, direct, auth name and auth email.
<div class="starter-template">
<h1>Recipes</h1>
</div>
<?php
try
{
$sql = 'SELECT recipe_id, recipe_name, recipe_ingred, recipe_direct, author_name, author_email FROM recipes';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching recipes: ' . $e->getMessage();
}
while ($row = $result->fetch())
{
$recipes[$row['recipe_id']] = $row;
}
?>
<p>Add a Recipe</p>
<?php foreach ($recipes as $id => $recipe): ?>
<blockquote>
<table class="table table-striped">
<tr>
<td><?php echo $recipe['recipe_name']; ?></td>
<td><?php echo $recipe['recipe_ingred']; ?></td>
<td><?php echo $recipe['recipe_direct']; ?></td>
<td><?php echo $recipe['author_name']; ?></td>
<td><?php echo $recipe['author_email']; ?></td>
</tr>
<?php htmlout($recipe_html); ?> |
edit |
delete
</table>
</blockquote>
<?php endforeach; ?>
You overwrite $recipe_html each time you assign a value to it
why not just echo out the table rows:
<table>
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?= $recipe['recipe_name']; ?></td>
<td><?= $recipe['recipe_ingred']; ?></td>
<td><?= $recipe['recipe_direct']; ?></td>
<td><?= $recipe['author_name']; ?></td>
<td><?= $recipe['author_email']; ?></td>
</tr>
<?php endforeach; ?>
</table>
EdIt as #Fred -ii- states, the table tags should be outside the loop
Everything looks correct up until your foreach.
<blockquote>
<table class="table table-striped">
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?php $recipe_html = $recipe['recipe_name']; ?></td>
<td><?php $recipe_html = $recipe['recipe_ingred']; ?></td>
<td><?php $recipe_html = $recipe['recipe_direct']; ?></td>
<td><?php $recipe['author_name']; ?></td>
<td><?php $recipe['author_email']; ?></td>
</tr>
<p> //seems you were missing opening <p> tag//
<?php htmlout($recipe_html); ?> |
edit | //can use shorthand here//
delete //can use shorthand here//
</p>
<?php endforeach; ?>
</table>
</blockquote>

Issue with getting data from HTML into jQuery

I'm trying to pass some data from HTML to jQuery, my code partially works, but since I have more than one tags with same class I don't know how to send data only from tag which is clicked. I tried to send data through javascript function but with no luck. Can someone take a look at my code and try to help me.
<div id="inboxWindow">
<table id="list_ofMessages">
<tr>
<td>id</td>
<td>From</td>
<td>Title</td>
<td>Date</td>
</tr>
<?php while($data = $query2->fetch_assoc()): ?>
<?php
$senderID = $data['senderID'];
$query3 = $con->query("select * from login where user_id = '$senderID'");
$name = $query3->fetch_assoc();
$name = $name['username'];
?>
<tr>
<?php if($data['opened'] == 1) : ?>
<td class="messageID"><?php echo $data['idmessage']; ?></td>
<td><?php echo $name; ?></td>
<td><a class="readMessageLink"><?php echo $data['title']; ?></a></td>
<td><?php echo $data['received']; ?></td>
<?php else : ?>
<td class="messageID"><b><?php echo $data['idmessage']; ?></b></td>
<td><b><?php echo $data['senderID']; ?></b></td>
<td><b><a class="readMessageLink"><?php echo $data['title']; ?></a></b></td>
<td><b><?php echo $data['received']; ?></b></td>
<?php endif; ?>
</tr>
<?php endwhile; ?>
</table>
</div>
<div id="messageWindow">
<label id="titleArea"></label><br><br>
<label>Message:</label><br>
<label id="contentArea"></label>
</div>
script.js
$(".readMessageLink").click(function(){
$.post("readMessage.php", {"id" : $(".messageID").html()}, function(data){
var obj = jQuery.parseJSON(data);
$("#titleArea").html("Title: " + obj.title);
$("#contentArea").html(obj.content);
});
$("#inboxWindow").slideToggle(300);
$("#messageWindow").slideToggle(300);
});
Using this code I always get messageID from first message, no matter on which one I click.
use
"id" : $(this).closest('tr').find(".messageID").text()
instead of
"id" : $(".messageID").html()
try this
"id" : $(this).closest('tr').find(".messageID").text();

Categories