Note that there are some explanatory texts on larger screens.

plurals
  1. POCan you put script tags in between php tags?
    primarykey
    data
    text
    <p>I'm trying to make a div fade out with jquery after the form validates the user input after pushing submit. I'm trying to avoid the form from fading out before it validates in case the user didn't enter the correct information.</p> <p>I would like to know if I can just add script tags in between my php tags, so that once the validation finishes, I just run the javascript real quick and then pick up with the rest of the php, like so:</p> <pre><code>&lt;?php $name = trim($_POST['name']); $email = $_POST['email']; $comments = $_POST['comments']; $site_owners_email = 'zeckdude@gmail.com'; // Replace this with your own email address $site_owners_name = 'Chris Seckler'; // replace with your name if (strlen($name) &lt; 2) { $error['name'] = "Please enter your name"; } if (!preg_match('/^[a-z0-9&amp;\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) { $error['email'] = "Please enter a valid email address"; } if (strlen($comments) &lt; 3) { $error['comments'] = "Please leave a comment."; } if (!$error) { require_once('phpMailer/class.phpmailer.php'); $mail = new PHPMailer(); $mail-&gt;From = $email; $mail-&gt;FromName = $name; $mail-&gt;Subject = "Website Contact Form"; $mail-&gt;AddAddress($site_owners_email, $site_owners_name); $mail-&gt;AddAddress('zeckdude@gmail.com', 'Chris Seckler'); $mail-&gt;Body = $comments; $mail-&gt;Send(); ?&gt; &lt;script type="text/javascript"&gt; $(function(){ $('#container').fadeOut(1000); }); &lt;/script&gt; &lt;?php echo "&lt;li class='success'&gt; Congratulations, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! &lt;/li&gt;"; echo nl2br("&lt;b&gt;Message Sent:&lt;/b&gt; From: $name Email: $email Message: $comments &lt;br/&gt;&lt;a href='http://www.google.com'&gt;Link&lt;/a&gt;"); } # end if no error else { $response = (isset($error['name'])) ? "&lt;li&gt;" . $error['name'] . "&lt;/li&gt; \n" : null; $response .= (isset($error['email'])) ? "&lt;li&gt;" . $error['email'] . "&lt;/li&gt; \n" : null; $response .= (isset($error['comments'])) ? "&lt;li&gt;" . $error['comments'] . "&lt;/li&gt;" : null; echo $response; } # end if there was an error sending ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload