hello je cherche a fignolé un petit plugin de formulaire spécifique qui envois des emails (pas de stokage en bdd)
j'arrive a générer les mes champs via des input html5
et je voudrais pouvoir mettre un fichier en PJ au email
via Jmail c'est pas trop complexe mais comme faire pour stocker temporairement la pj pour la mettre dans l'email ?
Merci par avance
j'arrive a générer les mes champs via des input html5
et je voudrais pouvoir mettre un fichier en PJ au email
via Jmail c'est pas trop complexe mais comme faire pour stocker temporairement la pj pour la mettre dans l'email ?
Merci par avance
Code PHP:
$list_fields = $field->parameters->get('form_fields');
if ($list_fields){
foreach( $list_fields as $list_fields_idx => $list_field ) {
//print_r ($list_field);
//check and create required class
$required ='';
if ($list_field->field_required){
$required="required";
}
//create field id
$field_id = preg_replace("#[^a-zA-Z-0-9]#", "", JText::_($list_field->field_label));
//create field value
$field_value = preg_replace("#[^a-zA-Z-0-9]#", "", JText::_($list_field->field_value));
//placeholder
$placeholder = ($label_position === 'placeholder') ? 'placeholder="'.$list_field->field_label.'"': '';
//create JText value
$field_label = JText::_($list_field->field_label);
if($list_field->field_type === 'text') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="text" name="'.$field_value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
if($list_field->field_type === 'email') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="email" name="'.$field_value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.' validate-email"></div>';
}
if($list_field->field_type === 'date') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="date" name="'.$field_value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
if($list_field->field_type === 'datetime-local') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="datetime-local" name="'.$field_value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
if($list_field->field_type === 'textarea') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><textarea rows="4" cols="50" name="'.$field_value.'" '.$placeholder.' aria-label="'.$field_label.'" id="'.$field_id.'" class="'.$required.'"></textarea></div>';
}
if($list_field->field_type === 'radio') {
$values_field = explode(";;",$list_field->field_value);
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$list_field->field_label.'</label>';
foreach( $values_field as $value_field ) {
$value = preg_replace("#[^a-zA-Z-0-9]#", "", JText::_($value_field));
$fields_display .= '<input type="radio" value="'.$value.'" name="'.$field_id.'" aria-label="'.JText::_($value_field).'" class="'.$required.'"><label for="'.$field_id.'">'.JText::_($value_field).'</label>';
}
$fields_display .='</div>';
}
if($list_field->field_type === 'checkbox') {
$values_field = explode(";;",$list_field->field_value);
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$list_field->field_label.'</label>';
foreach( $values_field as $value_field ) {
$value = preg_replace("#[^a-zA-Z-0-9]#", "", JText::_($value_field));
$fields_display .= '<input type="checkbox" value="'.$value.'" name="'.$field_id.'" class="" aria-label="'.JText::_($value_field).'" ><label for="'.$field_id.'">'.JText::_($value_field).'</label>'; //TODO add required system
}
$fields_display .='</div>';
}
if($list_field->field_type === 'select') {
$values_field = explode(";;",$list_field->field_value);
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$list_field->field_label.'</label><select id="'.$field_id.'" aria-label="'.JText::_($value_field).'"><option value="">'.JText::_('FLEXI_SELECT').'</option>';
foreach( $values_field as $value_field ) {
$value = preg_replace("#[^a-zA-Z-0-9]#", "", JText::_($value_field));
$fields_display .='<option value="'.$value.'" class="'.$required.'">'.JText::_($value_field).'</option>';
}
$fields_display .='</select></div>';
}
if($list_field->field_type === 'file') {
$fields_display .= '<h3>NOT COMPLETE FUNCTION</h3><div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="file" name="'.$field_id.'" accept="'.$value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
if($list_field->field_type === 'phone') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="phone" name="'.$field_id.'" pattern="'.$value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
if($list_field->field_type === 'hidden') {
$fields_display .= '<input type="hidden" name="'.$field_id.'" id="'.$field_id.'">';
}
if($list_field->field_type === 'freehtml') {
$fields_display .= '<div class="field"><p>'.$field_label.'</p><p>'.JText::_($list_field->field_value).'</p></div>';
}
if($list_field->field_type === 'url') {
$fields_display .= '<div class="field"><label for="'.$field_id.'" class="'.$class.'">'.$field_label.'</label><input type="url" name="'.$field_id.'" pattern="'.$list_field->field_value.'" id="'.$field_id.'" '.$placeholder.' aria-label="'.$field_label.'" class="'.$required.'"></div>';
}
}
}
$html = '
<form id="contact-form-'.$formid.'" method="POST" class="form-validate" enctype="multipart/form-data">
<fieldset>
'.$titleformD.'
'.$fields_display.'
'.$consent_field.'
'.$captcha_div.'
<input type="submit" name="submit" value="'.JText::_('FLEXI_FIELD_EMAIL_SUBMIT_LABEL_VALUE').'" class="'.$submit_class.'">
<input type="hidden" name="emailtask" value="plg.email.submit" />
<input type="hidden" name="emailto" value="'.$addr.'" />
<input type="hidden" name="itemid" value="'.$item->id.'" />
<input type="hidden" name="itemtitle" value="'.$item->title.'" />
<input type="hidden" name="itemalias" value="'.$item->alias.'" />
<input type="hidden" name="catid" value="'.$item->catid.'" />
<input type="hidden" name="return" value="" />
'.JHtml::_("form.token").'
</fieldset>
</form>';
Commentaire