Checkbox ajax form posts the word array to email - ajax

I am trying to make a booking form with checkboxes using an existing contact form.js script and mailhandler.php from template monster. All of the text and textarea inputs work fine but the checkboxes only return the word array.
Here's parts of the code:
html
<form action="bin/MailHandler.php" method="post" id="booking-form" >
<fieldset>
<div class="grid_12">
<div class="bookingformwrapper">
<div class="headerbar">WAXING</div>
intrested in:<br/>
<input type="checkbox" name="waxing[]" value="kidum_esek" id="wax1"/>aaa<br />
<input type="checkbox" name="waxing[]" value="mitug_esek" id="wax2"/>bbb<br />
<input type="checkbox" name="waxing[]" value="laikim" id="wax3"/>CCC<br />
<input type="checkbox" name="waxing[]" value="aher" id="wax4"/>DDD<br />
ajax jquery
,submitFu:function(){
var data = { 'waxing[]' : []};
$(":checked").each(function() {
data['waxing[]'].push($(this).val());
});
_.validateFu(_.labels)
if(!_.form.has('.'+_.invalidCl).length)
$.ajax({
type: "POST",
url:_.mailHandlerURL,
data:{
choice:'waxing[]',
name:_.getValFromLabel($('.name',_.form)),
email:_.getValFromLabel($('.email',_.form)),
phone:_.getValFromLabel($('.phone',_.form)),
fax:_.getValFromLabel($('.fax',_.form)),
state:_.getValFromLabel($('.state',_.form)),
message:_.getValFromLabel($('.message',_.form)),
message2:_.getValFromLabel($('.message2',_.form)),
datepicker:_.getValFromLabel($('#datepicker',_.form)),
owner_email:_.ownerEmail,
stripHTML:_.stripHTML
},
success: function(){
_.showFu()
}
})
},
php
<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";
if($POST['waxing[]'] !='nope'){
$messageBody .= '<p>Choice: ' . explode(",", $_POST['waxing[]']);
$messageBody .= '<br>' . "\n";
}
if($_POST['name']!='nope'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['state']!='nope'){
$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['datepicker']!='nope'){
$messageBody .= '<p>Date: ' . $_POST['datepicker'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Address: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST['message2']!='nope'){
$messageBody .= '<p>Notes: ' . $_POST['message2'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>
This is what gets returned on the email:
Choice: Array
Visitor: Father Christmas
Email Address: father#christmas.com
Phone Number: 01234 567890
Date: 25th December
Address: North Pole
Notes: Mince Pies
Where it says Choice: Array, I need it to give me the values of the selected/checked checkboxes.

Related

Hide datatable row when total equals 0

->addColumn('name', function ($customer) {
$d = '';
if (request('due_filter')) {
$sum = $customer->invoices->whereIn('status', array('due', 'partial'));
$due = $sum->sum('total') - $sum->sum('pamnt');
$d = '<span class="badge badge-danger">' . amountFormat($due) . '</span>';
}
return '<a class="font-weight-bold" href="' . route('biller.customers.show', [$customer->id]) . '">' . $customer->name . '</a>' . $d;
})
How can I hide customer row if total equals 0.00?

laravel livewire mount dynamic fields

I would like to have dynamic input fields with values ​​for all that are already entered in the db.
the following code works!
here the values ​​of the input extras.4 fields are displayed on the website
public function mount() {
$this->advettisment_extras = DB::table('advertisment_extras')
->where('advertisment_number', '=', $this->advertisment['advertisment_number'])
->where('user_id', '=', Auth::user()->id)->get()->toArray();
foreach ($this->advettisment_extras as $advettisment_extra) {
$this->extras = [
'4' => '12346548'
];
}
}
but when I try to dynamically search for and fill in the fields from db, the values ​​are not displayed.
foreach ($this->advettisment_extras as $advettisment_extra) {
$this->extras = [
$advettisment_extra->extra_id => $advettisment_extra->extra_value
];
}
can anyone help ?
<div class="row" wire:init="loadExtras">
#if(isset($categorie_extras))
#foreach($categorie_extras as $categorie_extra)
<div class="col-4 form-group">{!! getExtraField($categorie_extra->extra_id, $advertisment->advertisment_number) !!}</div>
#endforeach
#endif
</div>
and my getExtraField Function in helper.php
//Helper für Anzeige der Extra Felder
function getExtraField($extra_id, $advertisment_number) {
$field = '';
$option = '';
// Extra aus DB holen
$extra = \Illuminate\Support\Facades\DB::table('extras')->where('id', '=', $extra_id)->first();
$advertisment_extras = \Illuminate\Support\Facades\DB::table('advertisment_extras')
->where('advertisment_number', '=', $advertisment_number)
->where('user_id', '=', \Illuminate\Support\Facades\Auth::user()->id)->get();
switch ($extra->extra_form_item) {
case 'input':
foreach($advertisment_extras as $advertisment_extra) {
if ($advertisment_extra->extra_id == $extra->id ) {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
break;
} else {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
}
}
break;
case 'select':
$values = explode(',', $extra->extra_enum_select_values);
// Option des Select Feldes suchen
$field_1 = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><select name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="form-control" id="' . $extra->id . '">';
foreach ($values as $value) {
$option = $option .'<option value="'. $value . '">' . $value . '</option>';
}
$field_3 = '</select>';
$field = $field_1 . $option . $field_3;
break;
case 'checkbox' :
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><br><input type="checkbox" name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="" value="1" id="' . $extra->id . '">';
break;
}
return $field;
}
and my complete component:
//Helper für Anzeige der Extra Felder
function getExtraField($extra_id, $advertisment_number) {
$field = '';
$option = '';
// Extra aus DB holen
$extra = \Illuminate\Support\Facades\DB::table('extras')->where('id', '=', $extra_id)->first();
$advertisment_extras = \Illuminate\Support\Facades\DB::table('advertisment_extras')
->where('advertisment_number', '=', $advertisment_number)
->where('user_id', '=', \Illuminate\Support\Facades\Auth::user()->id)->get();
switch ($extra->extra_form_item) {
case 'input':
foreach($advertisment_extras as $advertisment_extra) {
if ($advertisment_extra->extra_id == $extra->id ) {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
break;
} else {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
}
}
break;
case 'select':
$values = explode(',', $extra->extra_enum_select_values);
// Option des Select Feldes suchen
$field_1 = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><select name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="form-control" id="' . $extra->id . '">';
foreach ($values as $value) {
$option = $option .'<option value="'. $value . '">' . $value . '</option>';
}
$field_3 = '</select>';
$field = $field_1 . $option . $field_3;
break;
case 'checkbox' :
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><br><input type="checkbox" name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="" value="1" id="' . $extra->id . '">';
break;
}
return $field;
}
my problem is that the value is not displayed in the fontend. That means the mount function does not work dynamically, but if I put it in directly as described above it works:
foreach ($xs as $x) {
$this->extras = [
'4' => '12345678'
];
}
but I would like to load the fields dynamically with values ​​like here:
foreach ($xs as $x) {
$this->extras = [
$x->extra_id => $x->extra_value,
];
}
Thanks for help :)

Ajax function not returing anything in response but post is working fine: Wordpress

I have this ajax script that action on a function in function.php to send an email after submitting the form. Data is posting but the function is not triggering and so the email is not sending , also script is not showing anything in response.
==================Jquery====================
jQuery('#quote-forms').submit(function(e) {
e.preventDefault();
var ocity = jQuery(".ocity").val();
var ostate = jQuery(".ostate").val();
var ozip = jQuery(".ozip").val();
var dataString = 'custom ocity='+ ocity + '&custom ostate=' + ostate + '&custom ozip=' + ozip;
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
action : 'quote_ajax_submission',
data: dataString,
success: function() {
alert("sent");
}
});
});
And here is my function in function.php file can you please check and let me know what is the issue so no response in return and email is not sending.
add_action('wp_ajax_quote_ajax_submission', 'quote_ajax_handler');
add_action('wp_ajax_nopriv_quote_ajax_submission','quote_ajax_handler');
function quote_ajax_handler(){
echo "helol";
$oCity = $_POST["custom ocity"];
$iZip = $_POST["custom ozip"];
$oState = $_POST["custom ostate"];
$dState = $_POST["dstate"];
$dZip = $_POST["dzip"];
$dCity = $_POST["dcity"];
$rNumbers = $_POST["room-numbers"];
$mDate = $_POST["mdate"];
$fName = $_POST["fname"];
$lName = $_POST["lname"];
$pEmail = $_POST["pemail"];
$pPhone = $_POST["pphone"];
$addtion_C = $_POST["additionC"];
$to = 'shoaibswl123#gmail.com';
$subject = 'Quote Request From '. $fName ;
$message = '<html><body>';
$message = '<div style="background:#CEE4ED; padding:10px;>';
$message = '<div style="margin-left:30px;">';
$message .= "<br>";
$message .= "<br>";
$message .= "<b>Hi Admin,</b>";
$message .= "<br>";
$message .= "<br>";
$message .= 'You have received a new quote from the site with the following information';
$message .= "<br>";
$message .= "<br>";
$message .= '<b>Address Information:</b>';
$message .= "<br>";
$message .= "<br>";
$message .= "<b>Origin City: </b>" .$oCity;
$message .= "<br />";
$message .= "<b>Origin Zip: </b>" . $iZip;
$message .= "<br />";
$message .= "<b>Origin State: </b>" . $oState;
$message .= "<br />";
$message .= "<b>Destination City: </b>" .$dCity;
$message .= "<br />";
$message .= "<b>Destination Zip: </b>" .$dZip;
$message .= "<br />";
$message .= "<b>Destination State: </b>" .$dState;
$message .= "<hr>";
$message .= "<br>";
$message .= "<br>";
$message .= '<b>Client Information:</b>';
$message .= "<br />";
$message .= "<br />";
$message .= "<b>First Name: </b>" .$fName;
$message .= "<br />";
$message .= "<b>Last Name: </b>" .$lName;
$message .= "<br />";
$message .= "<b>Primary Emai: </b>" .$pEmail;
$message .= "<br />";
$message .= "<b>Primary Phone: </b>" .$pPhone;
$message .= "<hr>";
$message .= "<br>";
$message .= "<br>";
$message .= '<b>Moving Information:</b>';
$message .= "<br>";
$message .= "<br />";
$message .= "<b>Moving Date: </b>" .$mDate;
$message .= "<br />";
$message .= "<b>Number of Rooms: </b>" .$rNumbers;
$message .= "<hr>";
$message .= "<br>";
$message .= "<br>";
$message .= '<b>Addition Comments :</b>';
$message .= "<br />";
$message .= '<p>'.$addtion_C.'</p>' ;
$message .= "<br>";
$message .= "<br>";
$message .= "<br>";
$message .= "<p>Thank you.</p>";
$message .= "</div></div>";
$message .= "</body></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$pEmail.'' . "\r\n";
if(wp_mail($to, $subject, $message, $headers)){
echo "<div class='success-message'>Message Has Been Sent Successfully..!</div>";
}else{
echo "<div class='success-message'>There is an error while sending message..!</div>";
}
die();
}
There was issue with action element in ajax call.
so we have updated the code like this and added the action element in the data array and its work as follows:
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: 'action=quote_ajax_submission&'+dataString,
success: function(data) {
alert("sent");
},
error: function(request, status, error){
alert(request.responseText);
}
});
});
So before the updated code the action element was like this:
action : 'quote_ajax_submission',
After update the code action like this...
data: 'action=quote_ajax_submission&'+dataString,

how to get onchange value after select navigation menu in magento?

hi all how to get onchange value after select navigation menu in magento?
i trying to following code in topmenu.phtmlbut it's not working proper showing page is not found
But it's not working properly. What do i do?
you can try something like this
<select id="nav" class="nav" onchange="if (this.value) window.location.href=this.value">
Update Topmenu.php code with below code.
Remove this:
$html .= '<option ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>';
if ($child->hasChildren()) {
if (!empty($childrenWrapClass)) {
$html .= '<div class="' . $childrenWrapClass . '">';
}
$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$html .= '</ul>';
if (!empty($childrenWrapClass)) {
$html .= '</div>';
}
}
$html .= '</option>';
Add below code:
$html .= '<option value="' . $child->getUrl() . '" '>'. $this->escapeHtml($child->getName()) . '</option>';
if ($child->hasChildren()) {
$html .= $this->_getHtml($child, $childrenWrapClass);
}
And update select onchange code with below code:
onchange="if (this.value) window.location.href=this.value"

magento how to make a parent menu link which has subcategories not clickable

Can someone help me with this please? I'm using Magento CE 1.8.0.0
magento how to make a parent menu link which has subcategories not clickable
I've tried the below codes, they don't work for me either.
app/code/core/Mage/Catalog/Block or Topmenu.php
if($category->getLevel()== 2 && $hasActiveChildren) {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' onclick="return false;">';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
} else {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
}
if ($category->getID()==[category ID]) {
$linkClass = 'class="no-click"';
$html[] = '<a href="javascript:void(0)"'.$linkClass.'>';
}
else{
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>;';
}
To make it works on top level only:
app/code/local/Mage/Page/Block/Html/Topmenu.php, line 126 replace this code
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
With :
if ($child->hasChildren() && $childLevel == 0 ) {
$html.= '<a href="#" ' . $outermostClassCode . ' onclick="return false;"><span>'
. $this->escapeHtml($child->getName()) . '</span></a>'."\n";
}
else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
}
Titonja has the answer here:
app/code/local/Mage/Page/Block/Html/Topmenu.php
Around line 126. Find this code:
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
Replace with:
if ($child->hasChildren()) {
$html.= '<a href="#" ' . $outermostClassCode . ' onclick="return false;"><span>'
. $this->escapeHtml($child->getName()) . '</span></a>'."\n";
}
else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
}
Clear cache. It works for me on Magento 1.8.0.0
For people with version 1.6.2, try this:
Look for the file: /app/code/core/Mage/Catalog/Block/Navigation.php
Replace line 268:
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
By this conditional:
$myParentIds = array(3,6,10);
if (in_array($category->getID(), $myParentIds)){
$linkClass = ' class="no-click"';
$html[] = '<a href="javascript:void(0)"'.$linkClass.'>';
}
else{
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
}
I hope this helps.
app/code/local/Mage/Page/Block/Html/Topmenu.php
Around line 126. Find this code:
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'. $this->escapeHtml($child->getName()) . '</span></a>';
Replace with:
if ($child->hasChildren() && $childLevel == 0) {
$html.= '<span>'. $this->escapeHtml($child->getName()) . '</span>'."\n";
} else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'. $this->escapeHtml($child->getName()) . '</span></a>';
}

Resources