Generated <form> inside Bootstrap-Modal needs to have a unique ID - forms

Well, I searched the whole Internet the last days to find a way to attach an unique ID and/or name to a GENERATED form inside a Bootstrap-Modal and I never succeeded...
I know I'm making mistakes in the code, but I ran out of ideas, I don't know what to use.
*Edit: I'm using Bootstrap 3, I created a table, having a live search field using JavaScript. The table rows are displayed from a database using a query. The last column of the row pops up a Bootstrap-Modal inside which a form is located, now here is the problem! I managed to assign a unique ID to each Modal and each Modal popup button, but the form! From here everything is mist.
Here is the code:
<div id="fm-<?php echo $row['PacientID']; ?>" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×
</button>
<h4 class="modal-title">
<b>
Fișa medicală #<?php echo $row['PacientID']; ?>: <?php echo $row['Name'].' '.$row['Surname']; ?>
</b>
</h4>
<?php
if (isset ($entranceSuccess))
{
?>
<div class="alert alert-success text-center">
<?php echo $entranceSuccess; ?>
</div>
<?php
}
?>
<?php
if (isset ($entranceError))
{
?>
<div class="alert alert-danger text-center">
<?php echo $entranceError; ?>
</div>
<?php
}
?>
</div>
<form data-toggle="validator" id="entranceForm" role="form" method="POST">
<div class="modal-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Data Intrării</th>
<th class="text-center">Medic Stomatolog</th>
<th class="text-center">Tratament</th>
<th class="text-center">Achitat</th>
</tr>
</thead>
<tbody>
<?php
$intrari = "SELECT * FROM intrari";
$intrariResults = $db -> query($intrari);
while ($row2 = $intrariResults -> fetch_assoc())
{
if ($row2['Pacient'] == $row['PacientID'])
{
?>
<tr class="text-center">
<th scope="row" class="text-center">
<?php echo $row2['EntranceDate'];?>
</th>
<td>
<?php
if ($row2['Medic'] == 1)
{
echo 'Dr. Carmen Pădurean';
}
else if ($row2['Medic'] == 2)
{
echo 'Dr. Claudiu Șuc';
}
else if ($row2['Medic'] == 3)
{
echo 'Dr. Mihaela Toncean';
}
else if ($row2['Medic'] == 4)
{
echo 'Dr. Alexandra Cenan';
}
else
{
echo 'MEDICUL STOMATOLOG NU A FOST DEFINIT!';
}
?>
</td>
<td>
<?php echo $row2['Treatment'];?>
</td>
<td>
<?php echo $row2['Achitat'];?>
</td>
</tr>
<?php
}
}
?>
<tr>
<th scope="row" class="text-center">
<div class="form-group">
<div class="input-group date entranceDateField">
<input type="text" class="form-control" id="entranceDate" name="entranceDate">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
</div>
</th>
<td>
<div class="form-group">
<select class="form-control" id="medic" name="medic">
<option value="1">Dr. Carmen Pădurean</option>
<option value="2">Dr. Claudiu Șuc</option>
<option value="3">Dr. Mihaela Toncean</option>
<option value="4">Dr. Alexandra Cenan</option>
</select>
</div>
</td>
<td>
<div class="form-group">
<input type="text" class="form-control" id="treatment" name="treatment">
</div>
</td>
<td>
<div class="form-group">
<input type="text" class="form-control" id="achitat" name="achitat">
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" id="addEntrance" name="addEntrance-<?php echo $row['PacientID'];?>">
<span class='glyphicon glyphicon-plus'></span> Adaugă Intrare
</button>
<?php
if (isset ($_POST['addEntrance-<?php echo $row[PacientID]; ?>']))
{
$entranceDate = $_POST['entranceDate'];
$pacient = $row['PacientID'];
$medic = $_POST['medic'];
$treatment = $_POST['treatment'];
$achitat = $_POST['achitat'];
$insertEntrance = "INSERT INTO intrari (EntranceDate, Pacient, Medic, Treatment, Achitat)
VALUES ('$entranceDate', '$pacient', '$medic', '$treatment', '$achitat')";
if (mysqli_query ($db, $insertEntrance))
{
$entranceSuccess = "Pacientul a fost adăugat în baza de date cu succes!";
}
else
{
$entranceError = "A apărut o eroare nedefinită! Suna-l pe Andrei (0755 696 200) și dictează-i: \"Error code: " . mysqli_error ($db) . "\"";
}
}
?>
</div>
</form>
</div>
</div>

By looking at your code, I see you are putting Modal HTML inside loop and by assigning unique id's to modal selector id="fm-<?php echo $row['PacientID']; ?>" trying to create multiple modals with unique id(s), it will cause the page to load slow and running queries inside each unique modal fetching the records from database when even you don't need fetched records on page load, it's not a good practice,
so let's go one step backward and remove the Modal from while loop and put it outside and remove <?php echo $row['PacientID']; ?> from Modal id selector.
<div id="fm" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
//Modal-Header, Modal-Body, Modal-Footer Comes Here
</div>
</div>
</div>
Now as you stated The last column of the row pops up a Bootstrap-Modal
Assuming you are triggering the modal with default behaviour with data attributes data-toggle="modal" data-target="#fm" and you have other information in other columns of rows like <?php echo $row['Name'].' '.$row['Surname']; ?> so you must have something like
<tr>
<td><?php echo $row['PacientID']; ?></td>
<td><?php echo $row['Name'].' '.$row['Surname']; ?></td>
<td><button type="button" class="btn btn-info" data-toggle="modal" data-target="#fm">Open Modal</button></td>
</tr>
Now Let's pass the pacientid and name to modal, Add data-attribute data-pacient to name col and to modal trigger button so above table col's will be
<tr>
<td><?php echo $row['PacientID']; ?></td>
<td><span class="pacientname" data-pacient="<?php echo $row['PacientID']; ?>"><?php echo $row['Name'].' '.$row['Surname']; ?></span></td>
<td><button type="button" data-pacient="<?php echo $row['PacientID']; ?>" class="btn btn-info" data-toggle="modal" data-target="#fm">Open Modal</button></td>
</tr>
With bootstrap modal event listener, you can pass the information to modal when modal about to show or shown
$(document).ready(function(){ //Dom Ready
$('#fm').on('show.bs.modal', function (e) { //Show event listener
var id = $(e.relatedTarget).data('pacient'); //Fetch val from modal data-attribute
var name = $('.pacientname[data-pacient="' + id +'"]').html(); //fetch val from selector `pacientname` data-attribute with match the val of modal button data-attribute
$(".pid").html(id); //selector inside modal header to pass id
$(".pname").html(name); //selector inside modal header to pass name
$("#addEntrance").val(id); //Passing id to hidden input in form, explained below
//Ajax method comes here which explains below
});
});
Modal-Header
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><span class="pid"></span> <span class="pname"></span></h4>
</div>
Fiddle Example to pass information to modal
Now about the query you are running inside modal, it can be done via Ajax method and display the information in modal. As we already have the required variable var id = $(e.relatedTarget).data('pacient'); can use it to fetch the required information via Ajax method
var dataString = 'id='+ id;
alert(dataString);
$.ajax({
type: "POST",
url: "file.php", //Create this file and handle query in it.
data: dataString,
cache: false,
success: function (data) {
$("#morecontent > tbody.showHere").html(data); //show fetched information from database
}
});
and file.php will be
<?php
//Database Connection Here
if(isset($_POST["id"])) {
$id = $_POST["id"]; //escape the string
$queryIntrari = "SELECT * FROM intrari WHERE Pacient = '$id'";
$intrariResults = $db -> query($queryIntrari);
while ($row2 = $intrariResults -> fetch_assoc()){
?>
<tr class="text-center">
<th scope="row" class="text-center">
<?php echo $row2['EntranceDate'];?>
</th>
<td>
<?php
if ($row2['Medic'] == 1)
{
echo 'Dr. Carmen Pădurean';
}
else if ($row2['Medic'] == 2)
{
echo 'Dr. Claudiu Șuc';
}
else if ($row2['Medic'] == 3)
{
echo 'Dr. Mihaela Toncean';
}
else if ($row2['Medic'] == 4)
{
echo 'Dr. Alexandra Cenan';
}
else
{
echo 'MEDICUL STOMATOLOG NU A FOST DEFINIT!';
}
?>
</td>
<td><?php echo $row2['Treatment'];?></td>
<td><?php echo $row2['Achitat'];?></td>
</tr>
<?php } } ?>
and the Modal-body, Modal-Footer with form and information fetched from database using Ajax will be like
<table class="table table-hover table-bordered" id="morecontent">
<form data-toggle="validator" id="entranceForm" role="form" method="POST">
<input type="hidden" id="addEntrance" name="addEntrance" value="">
<div class="modal-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Data Intrării</th>
<th class="text-center">Medic Stomatolog</th>
<th class="text-center">Tratament</th>
<th class="text-center">Achitat</th>
</tr>
</thead>
<tbody class="showHere">
//Information Fetched from Database Using Ajax will show Here
</tbody>
<tbody>
<tr>
<th scope="row" class="text-center">
<div class="form-group">
<div class="input-group date entranceDateField">
<input type="text" class="form-control" id="entranceDate" name="entranceDate">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
</div>
</th>
<td>
<div class="form-group">
<select class="form-control" id="medic" name="medic">
<option value="1">Dr. Carmen Pădurean</option>
<option value="2">Dr. Claudiu Șuc</option>
<option value="3">Dr. Mihaela Toncean</option>
<option value="4">Dr. Alexandra Cenan</option>
</select>
</div>
</td>
<td>
<div class="form-group">
<input type="text" class="form-control" id="treatment" name="treatment">
</div>
</td>
<td>
<div class="form-group">
<input type="text" class="form-control" id="achitat" name="achitat">
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">
<span class='glyphicon glyphicon-plus'></span> Adaugă Intrare
</button>
</div>
</form>
Note: Created a hidden input in <form> above, passed the value <?php echo $row['PacientID']; ?> to the hidden input when modal show, Post this hidden input along with other inputs when submitted the form in modal to insert or update values into database
an example here
Mission accomplished and hope you figure it out how to pass and get information in modal
Note: You can submit the modal form either the way you are doing or can also do it with Ajax and show success or error message inside modal without closing it and leaving the page but that's another story to tell some other time.
Happy Coding.

Related

PartialView on each list items

I have a in item list in each row has an edit button, which is supposed to open a partial view with the elements data to edit.
In the loop I use to fill tge datatable, I also create the partial views for each row element.
When I click the buton it always opens the first element partial view, even if I press the Nth element.
How do I get the code to open the corresponding partial view?
Code:
<table class="table table-hover" id="tabela_rota">
<thead>
<tr>
<th>
</th>
<th>
Cliente
</th>
<th>
Rota
</th>
<th>
Distância Ideal
</th>
<th>
Ativa
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<partial>
#{await Html.RenderPartialAsync("Edit", item);}
</partial>
<tr>
<td width="15">
</td>
<td width="15%">
#Html.DisplayFor(modelItem => item.id_cliente)
</td>
<td width="25%">
#Html.DisplayFor(modelItem => item.nome)
</td>
<td width="15%">
#Html.DisplayFor(modelItem => item.distancia_ideal)
</td>
<td width="10%">
#Html.DisplayFor(modelItem => item.activa)
</td>
<td>
<button type="button" class="btn btn-outline-primary" onclick="openNavEdit()">
Editar
</button>
<button type="button" class="btn btn-outline-danger">Delete</button>
</td>
</tr>
}
</tbody>
</table>
JS Function:
function openNavEdit() {
document.getElementById("mySidepanelEdit").style.width = "350px";
}
View:
#model GestaoCircuitos.Models.Rota
#{
ViewData["Title"] = "Editar";
}
<div id="mySidepanelEdit" class="sidepanel">
<div id="top_title">
<h6 id="nova_rota">Editar Rota</h6>
<button class="closebtn" onclick="closeNavEdit()">×</button>
</div>
<div class="row form-row-rotas">
<div class="col-12">
<form asp-action="Edit" class="form-rotas">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="id" />
<div class="form-label-group">
<input id="nome" class="form-control" placeholder="Nome" />
<label asp-for="nome" class="control-label">Nome</label>
<span asp-validation-for="nome" class="text-danger"></span>
</div>
<div class="form-label-group">
<input type="text" asp-for="distancia_ideal" class="form-control" placeholder="Distância ideal" />
<label asp-for="distancia_ideal" class="control-label">Distância ideal</label>
<span asp-validation-for="distancia_ideal" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="activa" /> Ativa
</label>
</div>
<div class="form-group">
<input type="submit" value="Editar" class="btn btn-primary" />
</div>
</form>
</div>
</div>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
It's because you're opening based on ID. An ID attribute needs to be unique throughout a document. If you select on an ID, you'll only get the first element.
You'll have to give each edit modal either a unique ID or a class to select from. Try this:
#model GestaoCircuitos.Models.Rota
#{
ViewData["Title"] = "Editar";
}
<div id="sidepanel-edit-#(item.id)" class=" sidepanel">
<div id="top_title">
<h6 id="nova_rota">Editar Rota</h6>
<button class="closebtn" onclick="closeNavEdit(#(item.id))">×</button>
</div>
<div class="row form-row-rotas">
<div class="col-12">
<form asp-action="Edit" class="form-rotas">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="id" />
<div class="form-label-group">
<input id="nome" class="form-control" placeholder="Nome" />
<label asp-for="nome" class="control-label">Nome</label>
<span asp-validation-for="nome" class="text-danger"></span>
</div>
<div class="form-label-group">
<input type="text" asp-for="distancia_ideal" class="form-control" placeholder="Distância ideal" />
<label asp-for="distancia_ideal" class="control-label">Distância ideal</label>
<span asp-validation-for="distancia_ideal" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="activa" /> Ativa
</label>
</div>
<div class="form-group">
<input type="submit" value="Editar" class="btn btn-primary" />
</div>
</form>
</div>
</div>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Above, we add a unique id for each edit edit form. Then we can reference those unique id attributes in the main template:
<table class="table table-hover" id="tabela_rota">
<thead>
<tr>
<th>
</th>
<th>
Cliente
</th>
<th>
Rota
</th>
<th>
Distância Ideal
</th>
<th>
Ativa
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<partial>
#{await Html.RenderPartialAsync("Edit", item);}
</partial>
<tr>
<td width="15">
</td>
<td width="15%">
#Html.DisplayFor(modelItem => item.id_cliente)
</td>
<td width="25%">
#Html.DisplayFor(modelItem => item.nome)
</td>
<td width="15%">
#Html.DisplayFor(modelItem => item.distancia_ideal)
</td>
<td width="10%">
#Html.DisplayFor(modelItem => item.activa)
</td>
<td>
<button type="button" class="btn btn-outline-primary" onclick="openNavEdit(#(item.id)">
Editar
</button>
<button type="button" class="btn btn-outline-danger">Delete</button>
</td>
</tr>
}
</tbody>
</table>
and your Javascript would look like:
function openNavEdit(id) {
document.getElementById("sidepanel-edit-" + id).style.width = "350px";
}
function closeNavEdit(id) {
document.getElementById("sidepanel-edit-" + id).style.width = "0";
}
Something to note, I'm assuming your model has an id attribute.

Array validation for table inputs in laravel 5.1

I am trying to give a validation for array inputs using table ,if the inputs are empty it should suppose to give a validation for each input box border as red color.
My table code is like we can add multiple no of rows by click add button like
My table view
My validations are coming like as in the below image shown
My current validation output
and i want validation something like as below using $errors and has-feedback in bootstrap laravel
My desired output
table view code:
<form action="{{ url('/executor/event') }}" method="post" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<table class="table table-bordered table-striped-col nomargin" id="table-data">
<tr align="center">
<td>Event Name</td>
<td>Event Code</td>
<td>Event Date</td>
<td>City</td>
<td>Country</td>
</tr>
<tr>
#if(null != old('eventname'))
#for($i=0;$i<count(old('eventname'));$i++)
<td>
<div class="form-group has-feedback {{ $errors->has('eventname'.$i) ? 'has-error' : '' }}" id="">
<input type="text" class="form-control " autocomplete="off" name="eventname[]" value="{{old('eventname'.$i)}}">
#if ($errors->has('eventname'.$i))
<p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
{{ $errors->first('eventname'.$i) }}</p>
#endif
</div>
</td>
#endfor
#else
<td>
<div class="form-group has-feedback {{ $errors->has('eventname') ? 'has-error' : '' }}" id="">
<input type="text" class="form-control " autocomplete="off" name="eventname[]" >
#if ($errors->has('eventname'))
<p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
{{ $errors->first('eventname') }}</p>
#endif
</div>
</td>
#endif
<td>
<input type="text" class="form-control" autocomplete="off" name="eventcode[]" >
</td>
<td>
<input type="text" class="form-control dob" autocomplete="off" name="date[]" >
</td>
<td>
<input type="text" class="form-control" autocomplete="off" name="city[]" >
</td>
<td>
<input type="text" class="form-control" autocomplete="off" name="country[]" >
</td>
<td>
<input type="button" value="+" class="add btn btn-success">
<input type="button" value="-" class="delete btn btn-danger">
</td>
</tr>
</table>
</br>
<center> <button type="submit" class="btn btn-primary" name="submit">Submit</button></center>
</form>
my controller is like below:
public function postEvent( EventRequest $request ) {
$data = Input::get();
for($i = 0; $i < count($data['eventname']); $i++) {
$c= new Event();
$c->event = $data['eventname'][$i];
$c->eventcode = $data['eventcode'][$i];
$c->date = $data['date'][$i];
$c->city = $data['city'][$i];
$c->country = $data['country'][$i];
$c->save();
}
$request->session()->flash('alert-success', 'Event was successful added!');
return redirect('executor/all');
}
and then my validation code in EventRequest.php
public function rules()
{
foreach($this->request->get('eventname') as $key => $val)
{
$rules['eventname.'.$key] = 'required';
}
return $rules;
}
I am using has-feedback error code inside my table for the first input .But still the validations are coming in the same way i could not able to find what was the mistake in my code.
Any help would be appreciated.
Thank you

Magento Unable to post review

I am trying to add a review to a product in magento. However, submitting the review form of a product in the frontend gives me an "Unable to post review message".
I haven't found a solution to the problem, that's why im calling in your help :)
This is the code from my review form:
<div class="form-add">
<h2><?php echo $this->__('Write Your Own Review') ?></h2>
<?php if ($this->getAllowWriteReviewFlag()): ?>
<form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
<?php echo $this->getBlockHtml('formkey'); ?>
<?php echo $this->getChildHtml('form_fields_before') ?>
<h3><?php echo $this->__("You're reviewing:"); ?>
<span><?php echo $this->escapeHtml($this->getProductInfo()->getName()) ?></span>
</h3>
<div class="fieldset">
<?php if ($this->getRatings() && $this->getRatings()->getSize()): ?>
<h4><?php echo $this->__('How do you rate this product?') ?> <em class="required">*</em></h4>
<span id="input-message-box"></span>
<table class="data-table review-summary-table ratings" id="product-review-table">
<col width="1"/>
<col/>
<col/>
<col/>
<col/>
<col/>
<thead>
<tr>
<th> </th>
<th>
<div class="rating-box">
<span class="rating-number">1</span>
<span class="rating nobr"
style="width:20%;"><?php echo $this->__('1 star') ?></span>
</div>
</th>
<th>
<div class="rating-box">
<span class="rating-number">2</span>
<span class="rating nobr"
style="width:40%;"><?php echo $this->__('2 star') ?></span>
</div>
</th>
<th>
<div class="rating-box">
<span class="rating-number">3</span>
<span class="rating nobr"
style="width:60%;"><?php echo $this->__('3 star') ?></span>
</div>
</th>
<th>
<div class="rating-box">
<span class="rating-number">4</span>
<span class="rating nobr"
style="width:80%;"><?php echo $this->__('4 star') ?></span>
</div>
</th>
<th>
<div class="rating-box">
<span class="rating-number">5</span>
<span class="rating nobr"
style="width:100%;"><?php echo $this->__('5 star') ?></span>
</div>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->getRatings() as $_rating): ?>
<tr>
<th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
<?php foreach ($_rating->getOptions() as $_option): ?>
<td class="value"><label
for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>"><input
type="radio" name="ratings[<?php echo $_rating->getId() ?>]"
id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>"
value="<?php echo $_option->getId() ?>" class="radio"/></label></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="hidden" name="validate_rating" class="validate-rating" value=""/>
<script type="text/javascript">decorateTable('product-review-table')</script>
<?php endif; ?>
<ul class="form-list">
<li>
<label for="review_field"
class="required"><em>*</em><?php echo $this->__('Let us know your thoughts') ?></label>
<div class="input-box">
<textarea name="detail" id="review_field" cols="5" rows="3"
class="required-entry"><?php echo $this->escapeHtml($data->getDetail()) ?></textarea>
</div>
</li>
<li class="inline-label">
<label for="summary_field"
class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
<div class="input-box">
<input type="text" name="title" id="summary_field" class="input-text required-entry"
value="<?php echo $this->escapeHtml($data->getTitle()) ?>"/>
</div>
</li>
<li class="inline-label">
<label for="nickname_field"
class="required"><em>*</em><?php echo $this->__("What's your nickname?") ?></label>
<div class="input-box">
<input type="text" name="nickname" id="nickname_field" class="input-text required-entry"
value="<?php echo $this->escapeHtml($data->getNickname()) ?>"/>
</div>
</li>
</ul>
</div>
<div class="buttons-set">
<button type="submit" title="<?php echo $this->__('Submit Review') ?>" class="button">
<span><span><?php echo $this->__('Submit Review') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('review-form');
Validation.addAllThese(
[
['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function (v) {
var trs = $('product-review-table').select('tr');
var inputs;
var error = 1;
for (var j = 0; j < trs.length; j++) {
var tr = trs[j];
if (j > 0) {
inputs = tr.select('input');
for (i in inputs) {
if (inputs[i].checked == true) {
error = 0;
}
}
if (error == 1) {
return false;
} else {
error = 1;
}
}
}
return true;
}]
]
);
//]]>
</script>
<?php else: ?>
<p class="review-nologged" id="review-form">
<?php echo $this->__('Only registered users can write reviews. Please, log in or register', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
</p>
<?php endif ?>
Looks like the standard rwd theme layout. If i delete my custom one so the rwd default pops up it still doesn't work.
The url that i'm posting from is as following:
https://www.example.com/review/product/post/id/73/
Hope someone can help me in the right direction. It's driving me crazy!!!
I solved the problem myself.
It had nothing to do with the reviews themselves. My first thought was a module that blocked access to the reviews, and after searching in de controller for reviews we found out that the problem was a module that couldn't have a certain length of characters stored in the database. This somehow conflicted with the reviews post.
After contacting the developers of that module we were able to solve the problem. The module was MailPlus and we solved it by going to the module its configuration and edited the following for Main website:
After changing this the reviews form started working again.
Thanks everybody for helping me!

show the "add another" button when the form is successfully send using codeigniter

i have this form called news and events, I want that when the form is successfully saved, the table form will hide then the add another button will appear. Im using session set userdata so that when the form is successfully saved the add another button will appear then the table form will hide. my code runs well but the problem is, after it successfully send the add another button will not work here's my controller below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class News_and_events extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->model('admin_model', 'am');
}
public function index(){
if($this->session->userdata('logged_in')){
$this->data['title'] = 'News and Events | Spring Rain Global Consultancy Inc Admin Panel';
$this->data['logout'] = 'Logout';
$session_data = $this->session->userdata('logged_in');
$this->data['id'] = $session_data['id'];
$this->data['username'] = $session_data['username'];
$this->data['allData'] = $this->am->getAllData();
$this->load->view('pages/admin_header', $this->data);
$this->load->view('content/news_and_events', $this->data);
$this->load->view('pages/admin_footer');
}else{
redirect('login', 'refresh');
}
}
public function add(){
if($this->session->userdata('logged_in')){
$this->form_validation->set_rules('date', 'Date', 'trim|required|xss_clean');
$this->form_validation->set_rules('event', 'Event', 'trim|required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE){
$this->data['title'] = 'News and Events | Spring Rain Global Consultancy Inc Admin Panel';
$this->data['logout'] = 'Logout';
$session_data = $this->session->userdata('logged_in');
$this->data['id'] = $session_data['id'];
$this->data['username'] = $session_data['username'];
$this->data['allData'] = $this->am->getAllData();
$this->load->view('pages/admin_header', $this->data);
$this->load->view('content/news_and_events', $this->data);
$this->load->view('pages/admin_footer');
}else{
$array = array(
'Date' => $this->input->post('date'),
'Event' => $this->input->post('event'),
'Description' => $this->input->post('description')
);
$this->am->saveData($array);
$this->session->set_userdata('add_another', $array);
redirect('news_and_events', 'refresh');
}
}else{
redirect('homepage', 'refresh');
}
}
}
and my views
<div class="container" >
<br />
<br />
<br />
<ul id="nav">
<li><h4>Home</h4></li>
<li><h4>News and Events</h4></li>
<li><h4>Activities</h4></li>
</ul>
<div class="starter-template">
<h1>News And Events</h1>
<?php if($this->session->set_userdata('add_another')):?>
<div id="add_another" style="float:left;">
<input type="button" value="Add Another" class="btn btn-primary" />
</div>
<?php else: ?>
<form action="<?php echo base_url().'news-and-events/add'?>" method="post">
<?php echo validation_errors('<div class="error">', '</div>');?>
<table class="table-striped">
<tr>
<td>Date: </td>
<td><input type="text" id="datepicker" name="date" value="<?php echo set_value('date');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td >Event: </td>
<td ><input type="text" name="event" value="<?php echo set_value('event');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="20%">Description: </td>
<td><textarea cols="30" rows="5" name="description" ><?php echo set_value('description');?></textarea></td>
</tr>
<tr>
<td width="20%"> </td>
<td><input type="submit" value="Add" class="btn btn-success" /></td>
</tr>
</table>
</form>
<?php endif; ?>
<br />
<br />
<table class="table" >
<tr>
<th>Date</th>
<th width="51%">Event</th>
<th>Description</th>
<th>Options</th>
</tr>
<?php foreach($allData as $allData): ?>
<tr>
<td><?php echo $allData->Date; ?></td>
<td><?php echo $allData->Event; ?></td>
<td></td>
<td></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div><!-- /.container -->
<script>
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: "yy-mm-dd"
});
</script>
in my views file ive added there the if else statement $this->session->set_userdata('add') just below the h1 tag which is news and events this will trigger the statement when the form is successfully saved!
can someone help me figured this out? or how to do this correctly?
any help is much appreciated! thanks!
istead of this line
<?php if($this->session->set_userdata('add_another')):?>
use this
<?php if($this->session->userdata('add_another')):?>
and in your controller before loading the view add this line
$this->session->set_userdata('add_another',1);

Zend: How do i create custom form elements using setDecorators()?

I need the form html like below:
<form>
<div class="es_form_txt">Name</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Gender</div>
<div class="es_form">
<input type="radio" value="" name=""> Male
<input type="radio" value="" name=""> Female
<input type="radio" value="" name=""> Other
</div>
<div class="clear1"></div>
<div class="es_form_txt">Country Code</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Phone</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="clear1"></div>
<div class="es_form"> </div>
<div class="es_form"><input type="button" class="button" value="Update"></div>
<div class="clear"></div>
</form>
I tried all sorts of solution in here not working! Could anyone point me in right direction?
I find that when I need to display specific HTML when using Zend_Form the most reliable solution is usually to use the ViewScript decorator.
Build a normal form using Zend_Form.
<?php
//application/forms/Search.php
class Application_Form_Search extends Zend_Form
{
public function init()
{
$this->setMethod('POST');
//assign the view script to the decorator, this can also be done in the controller
$this->setDecorators(array(
array('ViewScript', array(
'viewScript' => '_searchForm.phtml'
))
));
// create new element
$query = $this->createElement('text', 'query');
// element options
$query->setLabel('Search Keywords');
// add the element to the form
$this->addElement($query);
//submit element
$submit = $this->createElement('submit', 'search');
$submit->setLabel('Search Site');
$submit->setDecorators(array('ViewHelper'));
$this->addElement($submit);
}
}
Then build the actual script used to render the form.
<!-- ~/views/scripts/_searchForm.phtml -->
<article class="search">
<!-- set the action and the method -->
<form action="<?php echo $this->element->getAction()?>" method="<?php echo $this->element->getMethod()?>">
<table>
<tr>
<!-- you can render individual decorators. -->
<th><?php echo $this->element->query->renderLabel()?></th>
</tr>
<tr>
<td><?php echo $this->element->query->renderViewHelper()?></td>
</tr>
<tr>
<!-- or you can render a complete element -->
<td><?php echo $this->element->search?></td>
</tr>
</table>
</form>
</article>
This currently renders as:
<article class="search">
<form action="/video/index/display" method="post">
<table>
<tr>
<th>
<dt id="query-label">
<label for="query" class="optional">Search Keywords</label>
</dt>
</th>
</tr>
<tr>
<td>
<input type="text" name="query" id="query" value="" placeholder="Movie Title" size="20">
</td>
</tr>
<tr>
<td>
<input type="submit" name="search" id="search" value="Search Video Collection!">
</td>
</tr>
</table>
</form>
</article>
Some experimentation will be required to get exactly the output you require.