I have a HTML form with a textarea in it.
When entering a text with some enters in it, my Javascript malformes and wont load.
The forms submits to a PHP script that outputs the javascript below.
How can I fix this?
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.phpregio=%&vakgebied=Loodgieter&disciplines=&bericht=aasdasd
asdasda
sdasdasd';
}
}
</script>
Change to this:
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.php?'
+ 'regio=%&vakgebied=Loodgieter&disciplines=&'
+ 'bericht=aasdasdasdasdasdasdasd';
}
}
UPDATE: It seems that your php variable $bericht has line returns in it. Let's sanitize the variable to remove spaces and line returns like so:
$bericht = str_replace(array(' ', "\n", "\t", "\r"), '', $bericht);
Then you can use your code as before. To be safe, I would sanitize all your php variables that are going to be dropped right into javascript.
<HTML>
<HEAD>
<script type=\"text/javascript\">
function confirmsms() {
var redirect = confirm(\"Er zullen $count smsjes worden verzonden, klik op OK om door te gaan\");
if (redirect == true) {
window.location.href = 'send.php?regio=$regio&vakgebied=$vakgebied2&disciplines=$disciplines&bericht=$bericht'; }
}
Looks like the problem is you are not encoding your URL! As in your problem you are passing data using GET method your data will be the part of the URL itself!
Simply use encodeURI() before sending! So your code should look like
function confirmsms() { var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan"); var encodedValue = encodeURI("YOUR TEXTAREA VALUE HERE"); if (redirect == true) { window.location.href = 'send.php?VAR1=VAL1&VAR2=VAL2'; }}
And at the back-end you can decode URL using string urldecode ( string $str )
Hope you this is what you are looking for!
Related
I am sending an id by fetch to php to fetch the name of a project. Now when I am sending this result to console to verify that it brings it correctly but it only brings a blank or empty space. Thank you very much if you got this far
Javascript, where you capture the id by clicking and sending the id by fetch
var enlaces=document.getElementsByClassName('enlace');
for(let el of enlaces){
el.addEventListener('click', obtener_id_proyecto);
}
function obtener_id_proyecto(e){
e.preventDefault();
console.log('presionaste en un proyecto');
var id_p=this.id;
//Enviando datos por Fetch
let datos=new FormData();
datos.append('id', id_p);
fetch('inc/funciones/funciones.php',{
method: 'POST',
headers:{'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(datos)
})
.then(function(response) {
if(response.ok) {
return response.text();
} else {
throw "Error en la llamada Ajax";
}
})
.then(function(datosRecididos){console.log(datosRecididos)});
}
PHP
function obtenerNombreProyecto(){
$id_proyecto=$_POST['id'];
include 'conexion.php';
try{
$sql= mysqli_query($conexion,"SELECT nombre FROM proyectos WHERE id = {$id_proyecto}");
return json_encode($sql);
} catch(Exception $e){
echo "Error! : ". getMessage($e);
return false;
}
}
Console screenshot
https://prnt.sc/9Cr8fKRuqAX1
Probably there is a problem with this address: './inc/funciones/funciones.php'. Are you sure about that? Why you put a . in the beginning of it?
There are a lot of questions, blog posts etc. to explain how to customise the beforeunload message a browser would emit upon navigating away from the page.
It all boils down to the following:
window.onbeforeunload = function() {
return 'Place your message here'
}
If you'd return an empty string, the browser's default, fully localized, message is returned:
window.onbeforeunload = function() {
return ''
}
I'm wondering if Javascript is able to do the inverse: getting/reading the default localized message. So for example in pseudo-code something like
const message = browser.messages.beforeunload
// Chrome EN : message = "Are you sure you want to leave this page?"
// Chrome NL : message = "Ben je zeker dat je deze pagina wilt verlaten?"
// Firefox : message = "This page is asking you to confirm that you want to leave..."
// ....
I'm having quite a problem to which other answers pose no solution.
I'm trying to print out double quotes in a string literal. I, however, keep getting errors.
This is the specific function:
app.put('/assignments/:name/assignee/:assignee', function (request, response) {
logic.examine(request, function (mail, jobtitle) {
if (mail !== request.params.assignee && jobtitle.indexOf('Personeel') === -1) {
response.sendStatus(401);
} else {
logs_logic.addLog(mail + ' heeft gebruiker met naam "' + request.params.assignee + '" toegekend aan opdracht met als naam "' + request.params.name + '".');
response.status(200).json(logic.changeAssignee(request.params.name, request.params.assignee));
}
});
});
The error message reads 'Invalid or unexpected token' pointed to the part after the third 'plus' (or concat) sign. So it starts at "toegekend"
Any ideas?
Thanks in advance!
use es6 template literas aka backticks which will create more clarity in statements.
`this is string ${some_variable} more text ${some_variable_2}`
logs_logic.addLog(`${mail} heeft gebruiker met naam " ${request.params.assignee} " toegekend aan opdracht met als naam " ${request.params.name} ".`);
Use backticks (`) to form the string instead of single quotes.
and use
${variable_name}
to use that variable in string.
Here is the example:
logs_logic.addLog(`${mail} heeft gebruiker met naam "${request.params.assignee}" toegekend aan opdracht met als naam "${request.params.name}".`);
Hope this helps.
Give the " literal a try and see if it works for you. Something like this: 'This is "quoted"'
I'm trying to consume a SOAP Web Service used in a PHP file.
When I access the PHP file directly, it works. (http://bacly.fr/baclymphp/getffbadsample.php)
When I try to access it from an AngularJS like this:
function loadwsffbad() {
var players={}
var urlphp="http://localhost/cordova/mbacly/www/php/";
$http.get(urlphp+"getffbadsample.php").then(function(data) {
players = data.data;
console.log(players);
},function(status) {
alert("pas d accès réseau");
});
}
I get this in console:
Fatal error: Class 'SoapClient' not found in C:\wamp\www\cordova\mbacly\www\php\getffbadsample.php on line 5
I saw in other posts that I need to check that SOAP is enabled on the server, which is the case (http://bacly.fr/baclymphp/info.php), As it works directly with the php file, I guess it is not the pb.
getffbadsample.php:
<?php
$clientSOAP = new SoapClient('http://ws.ffbad.com/FFBAD-WS.wsdl');
$Auth["Login"]="******";
$Auth["Password"]="*****";
//Encodage de vos identifiants en Json (sérialisation des objets)
$AuthJson = json_encode($Auth);
$Query["Function"]="ws_getresultbylicence";
$Query["Param"]["Licence"]="06468814";
$QueryJson = json_encode($Query);
//Appel de la fonction distante
$Return = $clientSOAP->getResult($QueryJson,$AuthJson);
echo $Return;
?>
Thank for your help.
please check with me where is the error in this ajax code to send 2 parameters:
var xhr = getXhr();
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200)
{
selects = xhr.responseText;
// On se sert de innerHTML pour rajouter les options a la liste
//document.getElementById('prjsel').innerHTML = selects;
}
};
xhr.open("POST","ServletEdition",true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
id=document.getElementById(idIdden).value;
fu=document.getElementById("formUpdate").value;
//alert(fu);
var i=1;
xhr.send("id=" +id+", fu="+i);
i cant got the value of fu i don't know why.
thanks
The contents of your xhr.send() need to be URL encoded. For example:
xhr.send("id=1&fu=2");
Basicallly, anything that goes inside the xhr.send() would be the same as the query string you'd set with a GET. In other words, what you have inside send should also work on the end of a URL:
http://www.mysite.com/path/to/script?id=1&fu=2
it is really strange because i am used to work with it like that.
so i changed to the next:
xhr.send( "id="+id+"&fu="+i);
and it works.
thanks for help.