Get subject heading in Prestashop contact form email template - smarty

I have a drop downselect for several subjects in my Prestashop contact form.
<select id="id_contact" name="id_contact" class="form-control" onchange="showElemFromSelect('id_contact', 'desc_contact')">
<option value="0">-- Please chose --</option>
<option value="1">Cancel order</option>
<option value="3">Check order</option>
<option value="2">Return a product</option>
</select>
Is there any possibility to create or to have the value of the subject chosen in the confirmation email received?:

If you added this subjects as contacts names in backoffice, then in controllers/front/ContactController method postProcess() find block:
$var_list = array(
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
);
and add $contact->name e.g. to {message}
'{message}' => '<br />Subject: '. $contact->name . '<br />' .Tools::nl2br(stripslashes($message)),

Related

How do I create insert related field value from id [Laravel]

First of all sorry if my title question doesn't make sense, since I don't know how to word my problem and my English not that great. Okay, so
I have my controller
Buy::create([
'master_item_id' => $request->master_item_id,
'quantity_item' => $request->quantity_item,
'price' => $request->price
]);
I have my view
<select id="master_item_id" name="master_item_id"
class="form-control #error('master_item_id') is-invalid #enderror">
<option></option>
#foreach($item as $value)
<option {{ old('master_item_id') ? 'selected' : '' }} value="{{ $value->id }}">
{{ $value->name_item }} |
Rp {{ number_format($value->price, 0, ',', '.')}}
</option>
#endforeach
</select>
How do I create insert 'price' from one form select above? I'm guessing you use where() or maybe find()? I've been flipping through website searching and couldn't find anything. Thanks!
Using the model called MasterItem, this could work:
Buy::create([
'master_item_id' => $request->master_item_id,
'quantity_item' => $request->quantity_item,
'price' => MasterItem::find($request->master_item_id)->price
]);
This does assume that master_item_id in your request represents the id or primary key of the MasterItem model.
If not, and you cannot use find() then this would also work:
Buy::create([
'master_item_id' => $request->master_item_id,
'quantity_item' => $request->quantity_item,
'price' => MasterItem::firstWhere('whatever_the_column_is_called', $request->master_item_id)->price
]);

How to convert select & options to Laravel Form Elements

I have the following select section in HTML and CSS taken from ADMIN LTE
<select class="form-control select2" style="width: 100%;">
<option selected="selected">Alabama</option>
<option>Alaska</option>
<option>California</option>
<option>Delaware</option>
<option>Tennessee</option>
<option>Texas</option>
<option>Washington</option>
</select>
I need to convert it to Laravel Form Elements and I tried as follows:
{{Form::select('filter_region', [
'1' => 'Alaska',
'2' => 'California',
'3' => 'Delaware',
], null, ['placeholder' => 'Alaska'],['class'=>'form-control select2'])}}
But the views are different
How to resolve this?

Select input with 2 empty option values

In my laravel 5.7/mysql 5 app I have boolean is_quiz field in my vote Table and in model I define:
protected $casts = [
'is_quiz' => 'boolean',
];
...
And array with possible values/keys for using of this fields
private static $voteIsQuizLabelValueArray = Array(1 => 'Is Quiz', 0 => 'Is Not Quiz');
in control I add empty value for empty selector:
$viewParamsArray['voteIsQuizValueArray'] = $this->SetArrayHeader(['' => ' -Select Is Quiz- '], Vote::getVoteIsQuizValueArray(false));
and this array has values:
$viewParamsArray['voteIsQuizValueArray']::Array
(
[] => -Select Is Quiz-
[1] => Is Quiz
[0] => Is Not Quiz
)
In my form this array as :
{{ Form::select('is_quiz', $voteIsQuizValueArray, isset($vote->is_quiz) ? $vote->is_quiz : '', [ "id"=>"is_quiz", "class"=>"form-control editable_field select_input " ] ) }}
and in rendered html-source I see 2 options selected :
<select id="is_quiz" class="form-control editable_field select_input valid" name="is_quiz" aria-invalid="false" aria-describedby="is_quiz-error"><option value="" selected="selected"> -Select Is Quiz- </option><option value="1">Is Quiz</option><option value="0" selected="">Is Not Quiz</option></select>
and validator.w3.org raised error here.
I see what is the reson of the syntax error, but I do not know is there is easy way to fix it ?
Thanks!
Form builder is deprecated since Laravel 5
Why are Form and HTML helpers deprecated in Laravel 5.x?
As one of options you can try use Laravel Collective
https://packagist.org/packages/laravelcollective/html
But IMO the best decision is to build select via blade:
<select id="is_quiz"
class="form-control editable_field select_input valid"
name="is_quiz"
aria-invalid="false"
aria-describedby="is_quiz-error"
>
#foreach ($voteIsQuizValueArray as $k => $v)
<option
value="{{ $k }}"
#if( $k === old('is_quiz', '') ) selected="selected" #endif
>{{ $v }}</option>
#endforeach
</select>

How to get values of multiple select in contact form magento?

I have a code like this on my form.phtml, its a custom multiple select.
<select name="projecttype[]" multiple="multiple">
<option value="" selected>Select...</option>
<option value="Kitchen remodeling">Kitchen</option>
<option value="Refacing">Reface</option>
<option value="Counter tops">Counters</option>
<option value="Bathroom remodeling">Bathrooms</option>
<option value="Flooring">Floors</option>
<option value="Lighting">Lights</option>
<option value="Other">Others</option>
</select>
Now my problem is, how could I get those values if lets say I select "Floors and Lights" in my contact form. Because in normal select option, I could have a Project Type: {{var data.projecttype}} in custom form Email Template. But this one is a multiple select. This is my first time to encounter a problem like this but I can't find a good source as my guide on internet that something a good guide for this. Hope someone could help and guide me with this.
If you need to get value of multiselect box, you can use jQuery for that. See the below sample code.
<select id="multipleSelect" name="projecttype[]" multiple="multiple">
<option value="" selected>Select...</option>
<option value="Kitchen remodeling">Kitchen</option>
<option value="Refacing">Reface</option>
<option value="Counter tops">Counters</option>
<option value="Bathroom remodeling">Bathrooms</option>
<option value="Flooring">Floors</option>
<option value="Lighting">Lights</option>
<option value="Other">Others</option>
</select>
<div onclick="javascript:getValues();">TEST ME</div>
<script type="text/javascript">
function getValues(){
var selectedValues = jQuery('#multipleSelect').val();
alert(selectedValues);//alert if you want to
}
</script>
When you click on TEST ME <div>, you can see the values selected.
The above is a demo code. You can change it as per your needs.
Did you tried in this way...
foreach ($_GET['projecttype'] as $selectedOption)
echo $selectedOption."\n";
I came up to my mind to create a new phtml, and i just make my own mail and add this code
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$hear = $_POST['hear'];
$projecttype = implode(', ', $_POST['projecttype']);
$comment = $_POST['comment'];
$to = 'webdev2all#gmail.com';
$subject = 'Contact Form';
$message = 'Name: ' . $name . "\r\n" .
'E-mail: ' . $email . "\r\n" .
'Telephone: ' . $telephone . "\r\n" .
'How did you hear about us: ' . $hear . "\r\n" .
'Project Type: ' . $projecttype . "\r\n\r\n" .
'Comment: ' . $comment;
$headers = 'From: '. $name .' '. $email . "\r\n" .
'Reply-To: webdev2all#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
I also change my form action to
action="<?php echo $actual_link; ?>"
now my contact page form is working as I needed...
thanks for the replies...

JHTML generic list add data attributes to options Joomla 2.5

I need to add data attributes to individual options in a JHtml generic list in Joomla 2.5.
In standard html, the select list looks like:
<select class="field" placeholder="<?php echo JText::_('COUNTRY')?>" name="country" id="country" autofocus="autofocus" autocorrect="off" autocomplete="off">
<option value="" selected="selected">Select Country</option>
<option value="Afghanistan" data-alternative-spellings="AF">Afghanistan</option>
<option value="Åland Islands" data-alternative-spellings="AX Aaland Aland" data-relevancy-booster="0.5">Åland Islands</option>
<option value="Albania" data-alternative-spellings="AL">Albania</option>
...
</select>
Normally when creating an option I would do:
$options=array();
$options[]=JHTML::_( 'select.option', "Afghanistan", "Afghanistan" );
$options[]=JHTML::_( 'select.option', "Albania", "Albania" );
...
$dropdown = JHTML::_('select.genericlist',$options,'country','id="country" autofocus="autofocus" autocorrect="off" autocomplete="off"','value','text',$default);
How would I add the data-alternative-spellings="AF" to each option?
Thanks
It is in fact possible:
$data = array(
array(
'value' => 'redapple',
'text' => 'Red apple',
'attr' => array('data-price'=>'5'),
),
array(
'value' => 'greenapple',
'text' => 'Green apple',
'attr' => array('data-price'=>'3'),
),
);
$options = array(
'id' => 'applesfield', // HTML id for select field
'list.attr' => array( // additional HTML attributes for select field
'class'=>'field-apples',
),
'list.translate'=>false, // true to translate
'option.key'=>'value', // key name for value in data array
'option.text'=>'text', // key name for text in data array
'option.attr'=>'attr', // key name for attr in data array
'list.select'=>'greenapple', // value of the SELECTED field
);
$result = JHtmlSelect::genericlist($data,'apples',$options);
This will result in:
<select id="applesfield" name="apples" class="field-apples">
<option value="redapple" data-price="5">Red apple</option>
<option value="greenapple" data-price="3" selected="selected">Green apple</option>
</select>
Explanation:
I had already extended JHtmlSelect and overridden genericlist() when I found out I really on needed to set an option for genericlist(): 'option.attr'.
The parameters of JHtmlSelect::genericlist() are rather complicated, but simply: if the third parameter is array and it's the last parameter you pass, it will be used to populate genericlist's options.
'option.attr' will set the key for your option's extra attributes. If this is set, you can add as many attributes to your options as you like, as shown in the $data array above.

Resources