How to change the Label Caption after submit?

dileepav
dileepav used Ask the Experts™
on
Hi Experts,

I have a contact form in a web site. When the user click the send button. It is sending the emails perfectly, that part is done. Let me come to the issue. Ths form is "self posting". I just wanted to give a "Thank You." message to the user below the send button. I already inserted a label in this form with no text. This is a PHP form. When the user click the send button, I wanted to display the Thank you Message in the created label. This label is inside a "td", and the id of the label is "lblMsgThanks".

Kindly guide me on this.

Thanks & Regards
Dileep.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
in the form, add onsubmit event as follow:
<form action="..." onsubmit="document.getElementById('lblMsgThanks').innerHTML = 'Thank You';">
...
</form>

Open in new window

I presume it was ajax posting. Or else, the page will get refreshed and the above method doesn't work for you. If that's the case, try the following:
<form action="..." method="post">
  <!-- your contact form elements here -->
  <input type="submit" name="submit" value="Send">
  <label id="lblMsgThanks"><?php if (isset($_POST['submit']) && $_POST['submit'] == 'Send') echo 'Thank You'; ?></label>
</form>

Open in new window

Author

Commented:
Hi,

This page is not an AJAX page.

Thanks
Dileep
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Then try my second suggestion. Render the label as:

<label id="lblMsgThanks"><?php if (isset($_POST['submit']) && $_POST['submit'] == 'Send') echo 'Thank You'; ?></label>

Given that your submit button named "submit" and its value is "Send". You must change that to suit your page values.

Cheers,
Tien

Author

Commented:
Hi,

Can you please suggest where I can give this code?

Thanks
Dileep
Can you post the contact form php file? I will make changes for you :D

Author

Commented:
Hi,

PFA to see the PHP file.

Thanks
Dileep.
Contact.txt
I changed two places:

First, form action just be empty if you want it to be submitted to itself. Secondly is where the label is. Please see the file attached.
Contact.txt

Author

Commented:
Hi Cooler Sport,

Thank you, This is working perfectly, I Just wated to add "name of the person" also with this Thank you message. Can we do this making some slight changes to the current code, after that we can close this question.

Thanks
Dileep.
See attached. If the name of the person is present, the message will be "Thank [their name]" otherwise, it will be "Thank You" by default.
Contact.txt

Author

Commented:
Thanks This isolution is working perfectly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial