0

In a php tag, I wrote this:

<?php echo '
<form method = "post" onsubmit="return confirm('test');">
</form>
'; ?>

I receive a syntax error: Parse error: syntax error, unexpected 'test' (T_STRING), expecting ',' or ';'

Might anyone know how to fix this?

Gin.A
  • 53
  • 7
  • what is the `\ ` at `onsubmit=\"...` for? And the error you get is a php (not js) error, isn't it? Please show the surrounding code and the line the error is at. – Jeff Dec 16 '18 at 01:46
  • Sorry, i've removed the backslash. And yes its a php error. – Gin.A Dec 16 '18 at 01:49
  • I've seen the article, but its somewhat general and I can't seem to zero in on what the precise solution might be here. – Gin.A Dec 16 '18 at 01:51
  • Can you post the PHP code from your page here so we can help? – Peter Dec 16 '18 at 01:52
  • Edited my question to reflect the original code – Gin.A Dec 16 '18 at 01:54

1 Answers1

1

' quatation will not work in string since you started string with single quatation try to escape with \ like \'

try this

<?php echo '
<form method = "post" onsubmit="return confirm(\'test\');">
</form>
'; ?>
İsmail Atkurt
  • 1,360
  • 1
  • 12
  • 17