У меня есть ошибка в поле после отправки. Ошибка Предупреждение: htmlspecialchars() ожидает, что параметр 1 является строкой, массив указан в /path/ on line 420. Ниже приведен фрагмент кода (420 строк)Предупреждение в поле
<table>
<tr>
<td rowspan="4" style="width: 100px; height:200px">
<div style="position:absolute; top:0; margin:25px">
<input type="checkbox" id="exhibition" name="exhibition" value="Speaker">
</div>
</td>
<td colspan="2" style="width:400px; height:50px"><b>Speaker</b></td>
</tr>
<tr>
<td style="width:130px; height:50px">Section:</td>
<td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields']); ?>"></td>
</tr>
<tr>
<td style="width:130px; height:50px">Topic report:</td>
<td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields']); ?>"></td>
</tr>
<tr>
<td style="width:130px; height:50px">Required hardware:</td>
<td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields']); ?>"></td>
</tr>
</table>
Этот отрезанный код связан с этим кодом php.
<?php
if (isset($_POST["submit"])) {
$surname = $_POST['surname'];
$name = $_POST['name'];
$institution = $_POST['institution'];
$post = $_POST['post'];
$degree = $_POST['degree'];
$title = $_POST['title'];
$mailing = $_POST['mailing'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$site = $_POST['site'];
$from = 'Energy-knutd';
$from .= "MIME-Version: 1.0"."\r\n" ."Content-type: text/plain; charset='utf-8'". "\r\n";
$to = '[email protected]';
$subject = 'Member';
$form = implode(", ", (array)$_POST['participation']);
$fields = implode(", ", (array)$_POST['fields']);
$exhibition = $_POST['exhibition'];
if($_POST['exhibition'])
{
$body ="From: $surname\n Surname: $name\n Institution: $institution\n Post: $post\n Degree: $degree\n Title: $title\n Mailing: $mailing\n Phone: $phone\n Email: $email\n Site: $site\n Form: $exhibition. $fields";
} else {
$body ="From: $surname\n Surname: $name\n Institution: $institution\n Post: $post\n Degree: $degree\n Title: $title\n Mailing: $mailing\n Phone: $phone\n Email: $email\n Site: $site\n Form: $form";
}
// Check if name has been entered
if(!$_POST['surname']){
$errSurname = 'Pleaes enter your surname';
}
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
if (!$_POST['institution']) {
$errInstitution = 'Please enter your name of institution';
}
if (!$_POST['post']) {
$errPost = 'Please enter your post';
}
if (!$_POST['mailing']) {
$errMailing = 'Please enter your mailing address';
}
if (!$_POST['phone']) {
$errPhone = 'Please enter your phone';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
if (!$_POST['confirm']) {
$errConfirm = 'You should confirm with this statement';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errSurname && !$errInstitution && !$errPost && !$errMailing && !$errPhone && !$errConfirm) {
if (mail ($to, $subject, $body, $from)) {
$result="<div class='alert alert-success'>Thank You $name! I will be in touch</div>";
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>
Вы хотите, чтобы вывести определенное поле в столбце, он говорит в ошибке, что функция принимает только строку – Derek
Похоже, что это массив, а не строка. Вы хотели называть hhtmlspecialchars ($ fields) вместо $ _POST ('fields')? – michaelp
"fields" - это массив. В нескольких местах вашего кода вы явно определяете его и используете его как массив. Ошибка просто говорит вам, что вызываемая вами функция не может быть вызвана в массиве. Что вы даже * пытаетесь сделать? – David