Im struglling to autopopulating with prototype an textarea field. When costumer click <a href="#" onclick="SubmitPayshop();"/>GERAR</a>, they get response from a php file and should populate the textarea field.
The code above sucessfuly populate a specific DIV (commented in code), but i need to populate textarea <textarea style="width: 100%;height: 45px;" type="text" title="<?php echo $this->__('Payshop') ?>" class="input-text required-entry" id="pay_check_no" name="payment[check_no]" /></textarea>
Was triyng .update $('pay_check_no').value='***response from php***'. But no luck.
Could someone help me please?
Regards and thx
<script>
function SubmitPayshop()
{
new Ajax.Request('/payshop.php', {
method: 'get',
onSuccess: successFunc,
onFailure: failureFunc
});
}
function successFunc(response){
if (200 == response.status){
alert("A sua referência foi criada com sucesso!");
}
var container = $('pay_check_no');
var content = response.responseText;
container.update(content);
}
function failureFunc(response){
alert("Ocorreu um erro. Se deseja este método contate a loja diretamente." );
}
</script>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" >
<div id="pay_check_no" name="payment[check_no]"></div>
<li>
<span class="input-box">
<textarea style="width: 100%;height: 45px;" type="text" title="<?php echo $this->__('Payshop') ?>" class="input-text required-entry" id="pay_check_no" name="payment[check_no]" /></textarea>
</span>
</li>
</ul>
You have two elements with same id="pay_check_no", and when you trying to change $('pay_check_no').value looks like $('pay_check_no') refers to 'div' element not to input, just try to use different ids
Try using $('pay_check_no').value
Also ID should be unique
<div **id="pay_check_no"** name="payment[check_no]"></div>
<li>
<span class="input-box">
<textarea ...**id="pay_check_no"** name="payment[check_no]" /></textarea>
</span>
</li>
Related
I'm using codeigniter and trying to pass content to the database using the WYSIWYG editor.
I installed the WYSIWYG into my VIEW like the below code.
<div class="blank">
<div class="blank-page">
<!------------- syam bek-------------->
<?php if(!empty($error)): ?>
<div class="alert alert-warning">
<strong>Warning!</strong> <?php echo $error; ?>
</div>
<?php endif;?>
<?php if(!empty($products)):?>
<?php $ver=array('id'=>'try','name'=>'try','class'=>'form-horizontal'); ?>
<?php echo form_open_multipart(base_url().'editproduct/edit',$ver);?>
<label>المنتج
<br>
<select class="selectpicker" data-show-subtext="true" data-live-search="true" name="select_product" onchange="[document.try.action='editproduct/show',document.try.submit()]">
<?php
if (count($products)>1) {
echo '<option selected></option>';
foreach ($products as $p):
echo "<option value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
elseif(count($products)==1){
foreach ($products as $p):
echo "<option selected value ='$p->p_id'>" . $p->p_name . "</option>";
endforeach;
}
?>
</select>
<?php if(count($products)==1){
$name=$p->p_name;
$details=$p->details;
$price=$p->p_price;
}else{
$name="";
$details="";
$price="";
}
?>
</label>
</br>
<label>اسم المنتج
<input type="text" name="name" value="<?php echo $name;?>" class="form-control"/>
</label>
<br>
<label>تفاصيل للمنتج
<input type="text" name="details" value="<?php echo $details;?>" class="form-control" />
</label>
<br>
<label>سعر المنتج
<input type="text" name="price" value="<?php echo $price;?>" class="form-control" />
</label>
<br>
<br>
<br>
<div class="container">
<div class="hero-unit">
<div id="alerts"></div>
<div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="icon-font"></i><b class="caret"></b></a>
<ul class="dropdown-menu">
</ul>
</div>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="icon-text-height"></i> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>
<li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>
<li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
</ul>
</div>
<div class="btn-group">
<a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
<a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
<a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="icon-strikethrough"></i></a>
<a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
<a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
<a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>
<a class="btn" data-edit="indent" title="Indent (Tab)"><i class="icon-indent-right"></i></a>
</div>
<div class="btn-group">
<a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>
<a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>
<a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>
<a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>
</div>
<div class="btn-group">
<a class="btn" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="icon-picture"></i></a>
<input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
</div>
<div class="btn-group">
<a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="icon-undo"></i></a>
<a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="icon-repeat"></i></a>
</div>
<input type="text" data-edit="inserttext" id="voiceBtn" x-webkit-speech="">
</div>
<div id="editor">
</div>
</div>
</div>
<button class="btn btn-warning" name="cancel" >الغاء</button>
<button type="submit" name="save" class="btn btn-primary">حفظ</button>
<button type="submit" name="del" class="btn btn-danger">حذف المنتج</button>
<?php echo form_close();?>
<?php else :?>
<?php echo "لايوجد منتجات ليتم التعديل عليها";?>
<?php endif;?>
</div>
</div>
check i trace the inspector from the broswer i found insertion happens in the <div id="editor">HERE</div>
i don't know to pass the DIV contents to the database, especially the DIV element not identified by name like other elements.
Thanks
You can use javascript and ajax to submit your form, this is rough outline of jquery solution
// listen for submit event on your form
$( "#try" ).submit(function( event ) {
event.preventDefault();
let content = $('#editor').val(); // get the value from the editor
let details = $("input[name='details']").val() // get the value of input with the name of 'details'
... // do the same for all other inputs
// validate inputs if desired
if(content == '') {
// for example do something if content is empty
return;
}
// collect all input data into one object
var data = {
content: content,
details: details,
...
}
// send ajax request to the server
$.ajax({
url : 'urlToYourBackendEndpoint',
type : 'POST',
data : data,
success : function(response) {
// check the response and redirect or show notice after submit here
},
error : function(request,error)
{
alert("Request: "+JSON.stringify(request));
}
});
});
I need to post data from a form that creates fields from looping through some ids, so the fields have the same id and names but different data which i need to pass to my controller an eventually save
My Form View
<form class="form" id="addForm">
<div class="panel-body">
<?php foreach ($lab_result->result() as $results){?>
<div class="form-group">
<div class="col-md-5">
<input type="hidden" id="request_details_id" name="request_details_id" class="form-control" value="<?php echo $results->id; ?>"/>
<label class="col-sm-12 control-label"><span class="text-warning"><strong>Requested Service : </strong></span> <span class="text-success"><?php echo $results->service_name; ?> - <?php echo $results->service_description; ?></span></label>
<label class="col-sm-12 control-label"><span class="text-warning"><strong>Service Costs : </strong></span> <span class="text-success">Ksh. <?php echo $results->service_price; ?></span></label>
</div>
<div class="col-sm-7">
<textarea class="form-control" rows="2" id="results" name="results" placeholder="Input Lab Results, if none type N/A"></textarea>
</div>
</div>
<?php }?>
</div><!-- panel-body -->
<div class="panel-footer">
<button type="submit" class="btn btn-primary">Send Results</button>
</div>
</form>
Ajax to post data
$.ajax({
url: '<?php echo base_url(); ?>laboratory/addLabResult',
type: 'post',
data: $('#addForm :input'),
dataType: 'html',
success: function(html) {
$('#addForm')[0].reset();
bootbox.alert(html, function()
{
window.location.reload();
});
}
});
If i print_r in my controller, I only see the post from the last row
You need to use input name in array format to upload all values
<input type="hidden" id="request_details_id" name="request_details_id[]" class="form-control" value="<?php echo $results->id; ?>"/>
and
<textarea class="form-control" rows="2" id="results" name="results[]" placeholder="Input Lab Results, if none type N/A"></textarea>
This is the predefined post function inside Magento controller.
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
$translate = Mage::getSingleton('core/translate');
/* #var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
$postObject = new Varien_Object();
$postObject->setData($post);
$error = false;
if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
//$error = true; //orignal code
$error = false;
}
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
Mage::log($post['producturl']);
if (!Zend_Validate::is(trim($post['producturl']) , 'NotEmpty')) {
$error = true;
}
//if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
// $error = true;
//}
Mage::log($error);
Mage::log($postObject);
if ($error) {
throw new Exception();
}
$mailTemplate = Mage::getModel('core/email_template');
/* #var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
}
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect('');
return;
} catch (Exception $e) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
When I log the producturl attribute, it prints the correct view.But I do not get that value in my email. How to get that value binded so it gets send to the email?
My form looks like this:
<form action="<?php echo $this->getUrl('contacts/index/post'); ?>" id="contactForm" method="post">
<div class="row">
<div class="col-sm-12">
<!--<label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>-->
<div class="input-box">
<input name="name" id="name" placeholder="Name*" title="<em>*</em><?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
</div>
</div>
<div class="col-sm-12">
<!--<label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>-->
<div class="input-box">
<input name="email" id="email" placeholder="Email*" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
</div>
</div>
<div class="col-sm-12">
<!--<label for="telephone" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Mobile') ?></label>-->
<div class="input-box">
<input name="telephone" id="telephone" placeholder="Mobile*" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text required-entry" type="text" />
</div>
</div>
<div class="col-sm-12">
<div class="input-box">
<input name="producturl" id="producturl" placeholder="Product URL*" title="<?php echo Mage::helper('contacts')->__('ProductURL') ?>" value="url hai bhai" class="input-text required-entry" type="text" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!--<label for="comment" class=""><?php echo Mage::helper('contacts')->__('Comment') ?></label>-->
<div class="input-box input-textarea">
<textarea name="comment" id="comment" rows="3" placeholder="Message" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class=" input-text" placeholder="<?php echo Mage::helper('contacts')->__('Comment') ?>" style="width: 100%; height: 15%;resize:none;"></textarea>
</div>
</div>
</div>
<div class="row" style="text-align: center">
<div class="col-sm-12" style="padding-top:2%">
<input type="text" name="hideit" id="hideit" value="url hai bhai" style="display:none !important;" />
<button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('BOOK A DESIGNER') ?></span></span></button>
</div>
</div>
</div>
</div>
So, the emails templates are html files that you can actually find in the folder app/locale/[some_locale]/template/ if your locale is english of the US then some_locale will be en_US, if that is french from Belgium, then it will be fr_BE, so that is the language code on 2 letter as defined by ISO 639-1 then an underscore _ and country code as defined by ISO 3166-1 alpha-2.
And the name of the file will be something you could find if you do a global search on the handle of the template you actually stated in you comment.
So here contacts_email_email_template is actually defined in app/code/core/Mage/Contacts/etc/config.xml as being the file contact_form.html :
<template>
<email>
<contacts_email_email_template translate="label" module="contacts">
<label>Contact Form</label>
<file>contact_form.html</file>
<type>text</type>
</contacts_email_email_template>
</email>
</template>
So if you go and edit app/locale/en_US/template/email/contact_form.html that I reproduced here below and in which I added your product url value, that should work :
<!--#subject Contact Form#-->
<!--#vars
{"var data.name":"Sender Name",
"var data.email":"Sender Email",
"var data.telephone":"Sender Telephone",
"var data.comment":"Comment"}
#-->
Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
<!-- this below line is actually what you are after -->
Product URL : {{var data.producturl}}
data, actually being the key of the array you are passing as the fifth argument of the function sendTransactional
Well if you wish add the product URL to the email you first need to get the product key and wrap it around the static getUrl function.
Mage::getUrl($_product->getUrlKey())
Next just assign the above code to a variable and use some jQuery / Javascript to append the url to the end of the content of the message body. Honestly I would not recommend you to do this.
i have a form that insert in dbase what i write
here is the form,
<form id="contact-form" class="bl_form text-center" action="<?php echo "index.php?page=rooms&room=$rid&rpw=$rpw&r=$r";
?>" method="post" novalidate>
<span class="field-wrap scrollimation fade-right">
<input type="hidden" id="contact-name" name="contactName" type="text"
class="label_better requiredField" data-new-placeholder="Name" placeholder="Name" value="<?php echo "$uid"; ?>" data-error-
empty="*Enter your name">
</span>
<span class="field-wrap scrollimation fade-left">
<label class="control-label" for="contact-message">Message</label>
<textarea id="contact-message" name="message" rows="1" class="label_better
requiredField" data-new-placeholder="Message" placeholder="Message" data-error-empty="*Enter your message"></textarea>
</span>
<p class="text-center"><button name="sy2" id="submit_post" type="submit" class="btn btn-meflat
icon-left" data-error-message="Error!" data-sending-message="Sending..." data-ok-message="Message Sent"><i class="fa fa-paper-
plane"></i>Send Message</button></p>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php echo "<postfield name=\"message\" value=\"$(message)\"/>"; ?>
</form>
and i want to put a ajax code that display this message from dbase
<?php echo make_clickable($tosay)."$link_delete"; ?>
Can someone provide me an example?Thank you
Look at this
Ajax tutorial for post and get
So, the jQuery
$('body').on('submit', '#contact-form', function(){
$.post({$(this).attr("action"), $(this).serialize(), function(data){
if(data){
alert(data.message);
}
}, 'json');
return false;
});
And the server side
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST'){
// do your thing here
echo json_encode(array("message" => make_clickable($tosay).$link_delete));
die();
}
?>
I need that the customer field is required, if it is empty when pressing the continue button, this not must allow continue to next step and it then should appear a message indicating that the field is empty and need be completed.
Please, i need a help or advice about how to could make the validation.
Using boostrap.
<ul class="nav nav-pills nav-justified" id="NotTab">
<li class="active disabledTab">1. <?php echo $tab_customer; ?></li>
<li class="disabled disabledTab">2. <?php echo $tab_payment; ?></li>
</ul>
<div id="tab-customer" class="tab-pane active">
<div class="control-group">
<label class="control-label" style="color: #F00;"><b><?php echo $entry_customer; ?></b></label>
<div class="controls">
<input type="text" name="customer" value="<?php echo $customer; ?>" class="span3" onclick="this.select();">
<input type="hidden" name="customer_id" value="<?php echo $customer_id; ?>">
<input type="hidden" name="customer_group_id" value="<?php echo $customer_group_id; ?>">
</div></div>
<div class="form-actions">
<button class="btn btn-primary prevtab" type="button" onclick="return showNext()"><span class="glyphicon glyphicon-arrow-right"></span> Next </button></div>
</div>
<script>
var $tabs = $('#NotTab li');
function showPrev() {
$tabs.filter('.active').prev('li').removeClass("disabled");
$tabs.filter('.active').prev('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");
})
}
function showNext() {
$tabs.filter('.active').next('li').removeClass("disabled");
$tabs.filter('.active').next('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");;
})
}
</script>
Thanks.
You can use a simple check, to check if the input is empty.
if( !$('[name=customer]').val() ) {
alert('Input is empty');
return;
}