$message->to($item);
}
}
+
$subject = '';
if ($page->form_prefix) {
$subject = '[';
$subject .= $subject_ ?? $page->form_prefix;
$subject .= '] ';
}else {
- $subject = '['.$subject_.'] ';
+ if($subject_) {
+ $subject = '[' . $subject_ . '] ';
+ }
}
if (isset($validatedData['subject'])) {
*
*/
- public function validation_form(Request $request, $validation){
+ public function validation_form(Request $request, $validation, $multiArray = false){
$messages = [
'*.required' => __('Veuillez remplir les champs obligatoires'),
'email.email' => __('Veuillez indiquer une adresse email valide'),
];
$validator = Validator::make($request->all(), $validation, $messages);
+
if ($validator->fails()) {
throw new ValidationException($validator);
}
$validator->validate();
return $validator->validated();
+
}
public function check_email_exist(Request $request) {
if (is_array($field)) {
foreach ($field as $keySubfield => $subfield) {
if (in_array($keySubfield, ['firstname', 'lastname', 'name', 'company', 'address', 'city'])) {
- $validation['address.' . $keySubfield] = 'required|string|max:255';
+ $validation['*'.'.'.$keySubfield] = 'required|string|max:255';
} elseif (in_array($keySubfield, ['zipcode'])) {
- $validation['address.' . $keySubfield] = 'required|numeric';
+ $validation['*'.'.'.$keySubfield] = 'required|numeric';
}
}
}
}
- $data = $this->validation_form($request, $validation);
+ $dataValidated = $this->validation_form($request, $validation, true);
$email = Client::getClientConnected()->email;
- $address = Client::getClientConnected()->address;
-
- if($address) {
- $addressToArray = json_decode($address, true);
-
- $checkBillingAddress = array_filter($addressToArray, function ($n) {
- return $n['billing_address'];
- });
- $checkDeliveryAddress = array_filter($addressToArray, function ($n) {
- return $n['delivery_address'];
- });
- if (isset($request->address['billing_address'])) {
- foreach ($addressToArray as $key => &$value) {
- $value['billing_address'] = "0";
- }
- $data['address']['billing_address'] = "1";
- } else {
- $data['address']['billing_address'] = "0";
- }
-
- if (isset($request->address['delivery_address'])) {
- foreach ($addressToArray as $key => &$value) {
- $value['delivery_address'] = "0";
- }
- $data['address']['delivery_address'] = "1";
-
- } else {
- $data['address']['delivery_address'] = "0";
- }
-
- foreach ($addressToArray as $key => &$value) {
- $value['id'] = $key;
- }
-
- $data['address']['id'] = $index;
- $addressToArray[$index] = (object) $data['address'];
- if (!$checkBillingAddress && !isset($request->address['billing_address'])) {
- $addressToArray[0]['billing_address'] = "1";
- }
- if (!$checkDeliveryAddress && !isset($request->address['delivery_address'])) {
- $addressToArray[0]['delivery_address'] = "1";
- }
- } else {
- $data['address']['billing_address'] = "1";
- $data['address']['delivery_address'] = "1";
- $addressToArray = [$data['address']];
- }
+ $addressToArray = array_map(function($n) {
+ $n['billing_address'] = strval(intval((bool)$n['billing_address']));
+ $n['delivery_address'] = strval(intval((bool)$n['delivery_address']));
+ return $n;
+ }, $request->all());
//
$addressToString = json_encode($addressToArray);
$index = $request->index;
$address = Client::getClientConnected()->address;
- $addressToArray = json_decode($address);
+ $addressToArray = json_decode($address,true);
+
+ $addressToArray[0]['delivery_address'] = intval($addressToArray[$index]['delivery_address']) ? "1" : strval(intval($addressToArray[0]['delivery_address']));
+ $addressToArray[0]['billing_address'] = intval($addressToArray[$index]['billing_address']) ? "1" : strval(intval($addressToArray[0]['billing_address']));
unset($addressToArray[$index]);
$addressToArray = array_values($addressToArray);
return null;
}
-
- public static function setTypeOfAddress($request, array $address) {
-
- if (isset($request->address['billing_address'])) {
- foreach ($address as $key => &$value) {
- $value['billing_address'] = "0";
- }
- $data['address']['billing_address'] = "1";
- } else {
- $data['address']['billing_address'] = "0";
- }
-
- if (isset($request->address['delivery_address'])) {
- foreach ($address as $key => &$value) {
- $value['delivery_address'] = "0";
- }
- $data['address']['delivery_address'] = "1";
-
- } else {
- $data['address']['delivery_address'] = "0";
- }
-
- return $data;
- }
}
}
)
},
- updateAddress(id) {
+ getAddressesData() {
+ const form_test = document.getElementById('addresses-form')
+ const forms = document.querySelectorAll('form[id^="update-address"]')
+ const formDataCollection = {},
+ keys = {};
+
+ forms.forEach(function(form,k){
+ formDataCollection[k] = {};
+ const form_ = document.getElementById(form.id)
+ for(let i = 0; i < form_.length; i++) {
+ if(form_[i].dataset.name !== undefined) {
+ if (form_[i].dataset.name.includes("_address")) {
+ if (!form_[i].checked) {
+ form_[i].value = ""
+ }else {
+ form_[i].value = "on"
+ }
+ }
+ formDataCollection[k][form_[i].dataset.name] = form_[i].value;
+ }
+ }
+ })
+
+ return formDataCollection
+ },
+ updateAddress() {
let root = this,
- form = document.getElementById(id),
- formId = '#'+form.getAttribute('id'),
- data = new FormData(form)
+ data = this.getAddressesData()
axios.post('/ajax/updateAddress', data)
.then(function (response) {
-<form :id="'update-address-'+index" class="form-portal max-w-half-form" @submit.prevent="updateAddress('update-address-'+index)">
+<form :id="'update-address-'+index" class="form-portal max-w-half-form" @submit.prevent="updateAddress">
<div class="form-errors mb-10" v-if="errorsForm['id'] === '#update-address-'+index">
<ul class="list-disc list-inside text-red">
<li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
<div class="fields grid">
<label class="form-input text-navy">
{{ __('Donner un nom à cette adresse') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.name" required="required" name="address[name]" />
+ <input class="py-3 mt-3" type="text" v-model="address.name" required="required" data-name="name" name="address[name]" />
</label>
<label class="form-input text-navy">
{{ __('Société') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.company" required="required" name="address[company]" />
+ <input class="py-3 mt-3" type="text" v-model="address.company" required="required" data-name="company" name="address[company]" />
</label>
<label class="form-input half text-navy">
{{ __('Prénom') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.firstname" required="required" name="address[firstname]" />
+ <input class="py-3 mt-3" type="text" v-model="address.firstname" required="required" data-name="firstname" name="address[firstname]" />
</label>
<label class="form-input half text-navy">
{{ __('Nom') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.lastname" required="required" name="address[lastname]" />
+ <input class="py-3 mt-3" type="text" v-model="address.lastname" required="required" data-name="lastname" name="address[lastname]" />
</label>
<label class="form-input text-navy">
{{ __('Adresse') }}<span>*</span>
- <textarea class="py-3 mt-3" required="required" v-model="address.address" name="address[address]">
+ <textarea class="py-3 mt-3" required="required" v-model="address.address" data-name="address" name="address[address]">
</textarea>
</label>
<label class="form-input half text-navy">
{{ __('Code postal') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.zipcode" required="required" name="address[zipcode]" />
+ <input class="py-3 mt-3" type="text" v-model="address.zipcode" required="required" data-name="zipcode" name="address[zipcode]" />
</label>
<label class="form-input half text-navy">
{{ __('Ville') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.city" required="required" name="address[city]" />
+ <input class="py-3 mt-3" type="text" v-model="address.city" required="required" data-name="city" name="address[city]" />
</label>
</div>
</div>
<div class="form-group">
<label class="label-checkbox flex">
- <input type="radio" :checked="default_billing_address !== 'billing'+index ? false : true" class="w-4 h-4" name="address[billing_address]" @click="default_billing_address = 'billing'+index" />
+ <input type="radio" :checked="default_billing_address !== 'billing'+index ? false : true" class="w-4 h-4" data-name="billing_address" name="address[billing_address]" @click="default_billing_address = 'billing'+index" />
<span class="ml-4">{{ __('Adresse de facturation par défaut') }}</span>
</label>
<label class="label-checkbox flex mb-6">
- <input type="radio" :checked="default_delivery_address !== 'delivery'+index ? false : true" class="w-4 h-4" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+index" />
+ <input type="radio" :checked="default_delivery_address !== 'delivery'+index ? false : true" class="w-4 h-4" data-name="delivery_address" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+index" />
<span class="ml-4">{{ __('Adresse de livraison par défaut') }}</span>
</label>
</div>
</span>
<button type="submit" class="form-submit-button btn btn-custom xs:w-full">
{{ __('Enregistrer les modifications') }}
- </button>
+ </button type="submit">
</div>
<button class="flex items-center mt-12" @click.prevent="deleteAddress(index, 'update-address-'+index)" v-if="addresses.length > 1">
@svg('icon-trash')