up
This commit is contained in:
+30
-3
@@ -48,9 +48,21 @@ try {
|
||||
}
|
||||
|
||||
if (!$input) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'JSON inválido o vacío', 'raw_input' => $rawInput]);
|
||||
exit;
|
||||
// Si no viene JSON válido, intentar leer datos from form-encoded POST
|
||||
if (!empty($_POST)) {
|
||||
$input = $_POST;
|
||||
// Si el formulario incluye template_params como JSON string, decodificarlo
|
||||
if (isset($input['template_params']) && is_string($input['template_params'])) {
|
||||
$decodedTp = json_decode($input['template_params'], true);
|
||||
if ($decodedTp !== null) {
|
||||
$input['template_params'] = $decodedTp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'JSON inválido o vacío', 'raw_input' => $rawInput]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
@@ -180,6 +192,21 @@ try {
|
||||
}
|
||||
$language = $input['language'] ?? 'es';
|
||||
$parameters = $input['parameters'] ?? [];
|
||||
// Also accept template_params (from form or hidden input)
|
||||
if ((empty($parameters) || $parameters === []) && isset($input['template_params'])) {
|
||||
$tp = $input['template_params'];
|
||||
if (is_string($tp)) {
|
||||
$decoded = json_decode($tp, true);
|
||||
if ($decoded !== null) {
|
||||
$parameters = $decoded;
|
||||
} else {
|
||||
// fallback: treat string as a single named parameter value (name)
|
||||
$parameters = ['name' => $tp];
|
||||
}
|
||||
} elseif (is_array($tp)) {
|
||||
$parameters = $tp;
|
||||
}
|
||||
}
|
||||
$componentsSimple = $input['components'] ?? null;
|
||||
|
||||
// Verificar plantilla en base de datos (opcional)
|
||||
|
||||
Reference in New Issue
Block a user