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!
Related
How I get my data array from view? and how to insert in my database?
my view, I try much code but still an error, sorry about my question and my bad English
<form role="form" action="<?php echo base_url().'potongan/validasi'?>" action="GET">
<div class="box-body">
<div class="box-header with-border">
<div class="row">
<div class="col-xs-3">
<label >NIM</label>
<input type="text" class="form-control" name="nim" id="nim" placeholder="NIM" value="<?php echo $nime ?>" readonly>
</div>
<div class="col-xs-3">
<label >Nama Mahasiswa</label>
<input type="text" class="form-control" name="namamhs" placeholder="Nama Mahasiswa" value="<?php echo $nim[0]->namamhs ?>" disabled>
</div>
<div class="col-xs-3">
<label >Jurusan</label>
<input type="text" class="form-control" name="jurusan" placeholder="Jurusan" value="<?php echo $nim[0]->jurusan ?>" disabled>
</div>
</div>
<br>
<div class="form-group">
<label >Kode Beasiswa</label>
<input type="text" class="form-control " name="kdbeasiswa" value="<?php echo $kdbeasiswa ?>" readonly>
</div>
<div class="form-group">
<label >Keterangan</label>
<input type="text" class="form-control " name="keterangan" value="<?php echo $keterangan ?>" readonly>
</div>
<div>
<table class="table table-bordered table-striped">
<tr>
<th></th>
<th>Kode</th>
<th>Deskripsi</th>
<th>Tahun Akademik</th>
<th>semester</th>
<th>Tagihan</th>
<th>Beasiswa</th>
<th>Terbayar</th>
<th>Potongan</th>
</tr>
<?php foreach ($nim as $n): ?>
<tr>
<td>
<input type="hidden" class="form-control " name="id[]" value="<?php echo $n->thakad.$n->smtakad.$n->kdkeu; ?>" maxlength="3" >
</td>
<td><input type="hidden" class="form-control " name="kdkeu[]" value="<?php echo $n->kdkeu; ?>" maxlength="3" ><?php echo $n->kdkeu; ?></td>
<td><?php echo $n->deskeu; ?></td>
<td><input type="hidden" class="form-control " name="thakad[]" value="<?php echo $n->thakad; ?>" maxlength="3" ><?php echo $n->thakad; ?></td>
<td><input type="hidden" class="form-control " name="smtakad[]" value="<?php echo $n->smtakad; ?>" maxlength="3" ><?php echo $n->smtakad_view; ?></td>
<td><?php echo $n->tagihan; ?></td>
<td><?php echo $n->beasiswa; ?></td>
<td><?php echo $n->terbayar; ?></td>
<td>
<input type="text" class="form-control " name="prosentase_bea[]" value="<?php echo $n->potongan; ?>" maxlength="3">
</td>
</tr>
<?php endforeach ?>
</table>
</div>
</div>
<br>
<button class="btn btn-info" style="float: right;">submit</button>
</div>
<!-- /.box-body -->
</form>
my controller looks like this when I submit no data insert to the database and error like
Filename: C:/xampp/htdocs/tagihan/system/database/DB_query_builder.php
Line Number: 1498
$data = array();
$count = count($this->input->post('device'));
for($i=0; $i<$count; $i++) {
$data[] = array(
$thakad= $this->input->get('thakad'),
$smtakad= $this->input->get('smtakad'),
$kb = $this->input->get('kdbeasiswa'),
$kk = $this->input->get('kdkeu'),
$nim= $this->input->get('nim'),
$pb = $this->input->get('prosentase_bea'),
$status = 1,
$user = $this->session->userdata('username'),
$kt = $this->input->get('keterangan'),
$curentDate = date("Y-m-d"));
}
$this->db->insert_batch('keu_beasiswapermhs',$data);
redirect('http://localhost/tagihan/potongan');
Make a habit using the proper MVC
VIEW
<form action="URL" method="post">
</form>
CONTROLLER
$this->model->function_name();
redirect('URL');
MODEL
function function_name(){
$dataArr = array(
'field_name'=>$this->input->post('form_input_name'),
);
$this->db->INSERT('tbl_name',$dataArr);
}
You have fields like "namamhs" and "jurusan" that are not being put into the db.
You do not need for or while loops to insert data
You are not assigning what fields in your db each posted item goes to. Your controller has no idea where each value should be inserted. Do not use get, you should use post. Here is an example for your controller you can adapt to your form:
$data = [
'url' => $this->input->post('url'),
'name' => $this->input->post('name'),
'genre' => $this->input->post('genre'),
'counter' => $this->input->post('counter'),
'type' => $this->input->post('type')
];
where 'url' is a field in your db that you are putting $this->input->post('url') into.
Next you check the values:
$this->form_validation->set_rules('url', 'url', 'required|trim');
$this->form_validation->set_rules('name', 'Name', 'required|trim|callback_trims');
$this->form_validation->set_rules('genre', 'Genre', 'required|trim');
$this->form_validation->set_rules('counter', 'Counter', 'numeric');
$this->form_validation->set_rules('type', 'Type', 'required|min_length[3]');
If the values pass the validation, inserting is simple
if( $this->form_validation->run() == FALSE) {
echo validation_errors();
}else
{
$this->db->insert('music', $data);
}
You do not need batch insert. Just use insert
Your $data array is empty...always check if array not empty before insert batch...that cause error DB_query_builder.php Line Number: 1498
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.
Cant figure the PROTOTYPE script for adding or removing a the css class name "selected" to img element based in click function (already done for Jquery...) but it must be in Prototype. And its driving me crazy. Cant make it work for prototype....
My original code is (Magento store)
<div class="block block-poll">
<div class="block-title">
<strong><span><?php echo $this->__('Community Poll') ?></span></strong>
</div>
<form id="pollForm" action="<?php echo $action ?>" method="post" onsubmit="return validatePollAnswerIsSelected();">
<div class="block-content">
<p class="block-subtitle"><?php echo $this->htmlEscape($poll->getPollTitle()); ?></p>
<?php if( $poll_answers ): ?>
<ul id="poll-answers">
<?php foreach( $poll_answers as $answer ): ?>
<li>
<input type="radio" name="vote" style ="display:none;" class="radio poll_vote" id="vote_<?php echo $answer->getId() ?>" value="<?php echo $answer->getAnswerId() ?>" />
<?php
$stripped = $answer->getAnswerTitle();
$stripped_final = str_replace(" ", "_", strtolower($stripped)); //Value (simplified)
?>
<span class="label"><label for="vote_<?php echo $answer->getId() ?>"><img src="http://www.passione.pt/media/poll/<?php echo $stripped_final; ?>.png" id="chooser" class="chooser" alt="<?php echo $this->htmlEscape($answer->getAnswerTitle()) ?>" onClick="document.getElementById('vote_<?php echo $answer->getId() ?>').checked =true;"/></label></span>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('poll-answers');</script>
<?php endif; ?>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Vote') ?>" class="button"><span><span><?php echo $this->__('Vote') ?></span></span></button>
</div>
</div>
</form>
</div>
<?php endif; ?>
For Jquery.
Could you transform for Prototype 1.7...?
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
var Chooser = $('#poll-answers img');
Chooser.click(function() {
$('.chooser').removeClass('selected');
if(!Chooser.hasClass('selected')) {
$(this).addClass('selected');
} else {
$(this).removeClass('selected');
}
});
</script>
Prototype version of that click handler (untested):
$('poll-answers').on('click', 'img', function(event, element) {
$$('.chooser').invoke('removeClassName', 'selected');
element.toggleClassName('selected');
});
Edit: Changed to toggleClassName as per #Victor's suggestion. +7 points for him, and from each to invoke thanks to #Geek Num. +7 points for him and 1 left over for me.
EDIT 051012:
Turns out that the issue was less to do with the forms being on one page but more to conflicts between prototype and jQuery; there was a inclusion of jQuery right at the bottom of the footer which was not set to no conflict. I simply added this after the inclusion of that particular jQuery:
<script type="text/javascript">
//<![CDATA[
$.noConflict();
//]]>
</script>
I'm accepting Pavel Novitsky's answer below because he mentioned, "If assuming that you have no form embedding or JavaScript errors your code should work.." and that made me realize that it might have something to do with Javascript.
I'm currently building an e-commerce site with Magento which requires for both the registration and login forms to sit on one page.
I have successfully integrated both forms on a single page but was not able to login or register.
Here's a very brief overview of how the forms are structured
<!--registration-->
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<!--// form input fields go here-->
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
<!--login-->
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<!--// form input fields go here-->
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
I noticed that the variable dataForm was being defined twice over so I switched one of them to dataForm02 to see if the submissions would go through - neither did. So after almost 6 hours of prodding, I decided to remove the javascript validation and to my surprise, the submission on both forms worked.
Does anyone have an idea why this is happening? It is good that I got the submissions on both forms through but this is definitely not ideal because there'd be no form of validations employed on the 2 forms. I'm close to throwing my computer out my 20th storey apartment.
you have one and the same form action for both login and register forms:
<?php echo $this->getPostActionUrl() ?>
This method is defined in different blocks for templates.
If assume that you have no form embedding or JavaScript errors your code should work.Hard to say something without real code.
Just one guess: do you have
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
or
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
</script>
?
Make sure you are using different id for forms in both registration and login forms and also make sure you are using same id in scripts. Seems like you have problem with login form ids. Use this for your login script.
<!--login-->
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<!--// form input fields go here-->
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
</script>
You can alternatively using xml you can achieve this functionality. Just you will need to edit customer.xml file. Replace with this one.
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml" />
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
<label>Form Fields Before</label>
</block>
</block>
</reference>
</customer_account_login>
Replace your theme/template/presistent/customer/form/register.phtml with this code and let me know the result.
<?php $login = new Mage_Customer_Block_Form_Login(); ?>
<div class="account-login">
<div class="page-title">
<h1><?php echo $login->__('Login or Create an Account') ?></h1>
</div>
<?php //echo $login->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo $login->getPostActionUrl() ?>" method="post" id="login-form">
<div class="col2-set">
<div class="col-1 new-users">
<div class="content">
<h2><?php echo $login->__('New Customers') ?></h2>
<p><?php echo $login->__('By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.') ?></p>
</div>
</div>
<div class="col-2 registered-users">
<div class="content">
<h2><?php echo $login->__('Registered Customers') ?></h2>
<p><?php echo $login->__('If you have an account with us, please log in.') ?></p>
<ul class="form-list">
<li>
<label for="email" class="required"><em>*</em><?php echo $login->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="login[username]" value="<?php echo $login->htmlEscape($login->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $login->__('Email Address') ?>" />
</div>
</li>
<li>
<label for="pass" class="required"><em>*</em><?php echo $login->__('Password') ?></label>
<div class="input-box">
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $login->__('Password') ?>" />
</div>
</li>
<?php echo $login->getChildHtml('form.additional.info'); ?>
<?php echo $login->getChildHtml('persistent.remember.me'); ?>
</ul>
<?php echo $login->getChildHtml('persistent.remember.me.tooltip'); ?>
<p class="required"><?php echo $login->__('* Required Fields') ?></p>
</div>
</div>
</div>
<div class="col2-set">
<div class="col-1 new-users">
<div class="buttons-set">
<button type="button" title="<?php echo $login->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($login->getCreateAccountUrl()) ?>';"><span><span><?php echo $login->__('Create an Account') ?></span></span></button>
</div>
</div>
<div class="col-2 registered-users">
<div class="buttons-set">
<?php echo $login->__('Forgot Your Password?') ?>
<button type="submit" class="button" title="<?php echo $login->__('Login') ?>" name="send" id="send2"><span><span><?php echo $login->__('Login') ?></span></span></button>
</div>
</div>
</div>
<?php if (Mage::helper('checkout')->isContextCheckout()): ?>
<input name="context" type="hidden" value="checkout" />
<?php endif; ?>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
</script>
</div>
<div class="account-create">
<div class="page-title">
<h1><?php echo $this->__('Create an Account') ?></h1>
</div>
<?php echo $this->getChildHtml('form_fields_before')?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<div class="fieldset">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
<ul class="form-list">
<li class="fields">
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
</li>
<li>
<label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
</div>
</li>
<?php if ($this->isNewsletterEnabled()): ?>
<li class="control">
<div class="input-box">
<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />
</div>
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
</li>
<?php endif ?>
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
<?php if ($_dob->isEnabled()): ?>
<li><?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?></li>
<?php endif ?>
<?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
<?php if ($_taxvat->isEnabled()): ?>
<li><?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?></li>
<?php endif ?>
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
<?php if ($_gender->isEnabled()): ?>
<li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
<?php endif ?>
</ul>
</div>
<?php if($this->getShowAddressFields()): ?>
<div class="fieldset">
<input type="hidden" name="create_address" value="1" />
<h2 class="legend"><?php echo $this->__('Address Information') ?></h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="company"><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" name="company" id="company" value="<?php echo $this->escapeHtml($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
</div>
</div>
<div class="field">
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
<div class="input-box">
<input type="text" name="telephone" id="telephone" value="<?php echo $this->escapeHtml($this->getFormData()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" />
</div>
</div>
</li>
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<li class="wide">
<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<li class="wide">
<div class="input-box">
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="input-text <?php echo $_streetValidationClass ?>" />
</div>
</li>
<?php endfor; ?>
<li class="fields">
<div class="field">
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
<div class="input-box">
<input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
</div>
</div>
<div class="field">
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
</div>
</div>
</li>
<li class="fields">
<div class="field">
<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
</div>
<div class="field">
<label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
<?php echo $this->getCountryHtmlSelect() ?>
</div>
</div>
</li>
</ul>
<input type="hidden" name="default_billing" value="1" />
<input type="hidden" name="default_shipping" value="1" />
</div>
<?php endif; ?>
<div class="fieldset">
<h2 class="legend"><?php echo $this->__('Login Information') ?></h2>
<ul class="form-list">
<li class="fields">
<div class="field">
<label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
<div class="input-box">
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</div>
</div>
<div class="field">
<label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
<div class="input-box">
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</div>
</div>
</li>
<?php echo $this->getChildHtml('form.additional.info'); ?>
<?php echo $this->getChildHtml('persistent.remember.me'); ?>
</ul>
<?php echo $this->getChildHtml('persistent.remember.me.tooltip'); ?>
</div>
<div class="buttons-set">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<p class="back-link"><small>« </small><?php echo $this->__('Back') ?></p>
<button type="submit" title="<?php echo $this->__('Submit') ?>" class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
</div>
<?php if (Mage::helper('checkout')->isContextCheckout()): ?>
<input name="context" type="hidden" value="checkout" />
<?php endif; ?>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
</div>
i am again posting this question as i was unable to do what i wanted to, and also didn't get the answer of my previous question. Hope, this time it will catch the eye of someone who can answer.
I have created a module which enables to submit a form in the backend just like news module and faqs module etc and shows the result in the grid.
But what i want now is that i must be able to save the form frontend and show the results in grid.
i was told that it can be done through indexcontroller.php of my module. So what i actually did was i copied the save action of adminhtml controller and try to use it in index controller.
public function postAction() {
if ($data = $this->getRequest()->getPost()) {
$model = Mage::getModel('events/events');
$model->setData($data)
->setId($this->getRequest()->getParam('id'));
try {
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
$model->setCreatedTime(now())
->setUpdateTime(now());
} else {
$model->setUpdateTime(now());
}
$model->save();
Mage::getSingleton('core/session')->addSuccess(Mage::helper('events')->__('Item was successfully saved'));
Mage::getSingleton('core/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError($e->getMessage());
Mage::getSingleton('core/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('core/session')->addError(Mage::helper('events')->__('Unable to find item to save'));
$this->_redirect('*/*/');
}
/* testing */
and in frontend i created a phtml file :
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<form action="<?php echo $this->getPostActionUrl(); ?>" method="post" enctype="multipart/form-data" id="events_form">
<div class="fieldset">
<ul class="form-list">
<li>
<label for="title"><em>*</em><?php echo Mage::helper('events')->__('Title:') ?></label>
<div class="input-box">
<input style="font-size:14px;" name="title" id="content" value="" class="input-text required-entry" type="text" size="29"/>
</div>
</li>
<li class="wide">
<label for="content" class="required"><em>*</em><?php echo Mage::helper('events')->__('Description:') ?></label>
<div class="input-box">
<textarea name="content" id="content" title="<?php echo Mage::helper('events')->__('Description') ?>" class="input-text required-entry" style="font-size:14px;" name="overview" cols="55" rows="30"></textarea>
</div>
</li>
</ul>
</div>
<div class="buttons-set">
<p class="required"><?php echo Mage::helper('events')->__('* Required Fields') ?></p>
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
<button type="submit" title="<?php echo Mage::helper('events')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('events')->__('Submit') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var eventsForm = new VarienForm('events_form', true);
//]]>
</script>
But no luck :( can anyone please tell me how to get it done.