PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 6, 2022

[FIXED] How to display $name Input that a user submitted in a form within a $alert when user pushes the submit button?

 July 06, 2022     forms, html, javascript, php, phpmailer     No comments   

Issue

I am stuck and hoping someone can help.

I am trying to get the user's input (their $name) to show in the $alert'' when user submit form. Example: User types in to the form the following: ** Name: Joe , Tel: XXX.XXX.XXXX , Email: Joe@example.com *** and pushes submit.

-- page refreshes and says. "Message sent Joe, thank you for contacting us!"

$mail->send();
     $alert = <div class="alert-success">'
                     <span>Message sent $name, thank you for contacting us!</span> 
                    </div>'; 

Solution

You need to fix your typos, like this:

$mail->send();
     $alert = '<div class="alert-success">'.
                     '<span>Message sent '.$name.', thank you for contacting us!</span>'. 
                    .'</div>'; 

Now that you have a template in $alert you will need to make sure that you display it. The simplest way to do so is to echo it, like

echo $alert;

But you may need to display it somewhere else than the current position. Also, PHP is a template language as well, so in some environments you can do something like

$mail->send(); ?>
     <div class="alert-success">
                     <span>Message sent <?php echo $name; ?>, thank you for contacting us!</span> 
                    </div>
<?php


Answered By - Lajos Arpad
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing