I am working in Dreamweaver CS4 and have a contact form. I am using PHP to send the info. I have a disabled textbox that I want to use to display whether the contact form was sent successfully or failed. How would I send a success or failure message to this disabled textbox after the submit button is clicked? Thanks in advance!
11 9188 kovik 1,044
Recognized Expert Top Contributor
Dreamweaver is just an editor and has no effect on what you will be doing. Why are you using a text box for form feedback? And why do you expect this to be done in the same page?
Is your form processing performed purely server-side or client-side with AJAX?
code green 1,726
Recognized Expert Top Contributor
A simple example using pseudo code - if(isset($_POST['submit']))
-
echo '<input type="text" value="'.$message.'"/>';
-
else
-
echo '<input type="text" value=""/>disabled';
kovik 1,044
Recognized Expert Top Contributor
I think you meant to place "disabled" inside of the element as an attribute, not outside of it.
And OP said the textbox is *always* disabled. I'd just like for him to explain what he is trying to accomplish, as I have never seen his methodology before.
kovik,
I want to show the user some sort of notification that the message they sent using the contact form on the website was sent successfully. So, I want to display a message, like "Your email was sent successfully," in the textbox after they click the submit button.
kovik 1,044
Recognized Expert Top Contributor
Then do it the normal way: By showing them the messages. A good way to do this, in its most basic form, is a boolean variable to indicate success and an array to indicate error messages. Here's an example controller and view file: Controller: - <?php
-
$success = false;
-
$errors = array();
-
-
if (!empty($_POST)) { // Form has been submitted
-
// Validate all form elements and add errors
-
// to the $errors array when invalid
-
if (empty($_POST['name'])) {
-
$errors[] = 'Name must be filled.';
-
}
-
-
// Perform the operation if the form is valid
-
if (empty($errors)) {
-
// Do stuff here
-
$success = true; // Set $success = true if successful
-
}
-
}
-
?>
View: - <?php if ($success) { ?>
-
<p>Successful!</p>
-
<?php } else { ?>
-
<form method="post" action="#">
-
<?php if (!empty($errors)) { ?>
-
<ul>
-
<?php foreach ($errors as $error) { ?>
-
<li><?php echo $error; ?></li>
-
<?php } ?>
-
</ul>
-
<?php } ?>
-
<input type="text" name="name" />
-
<button type="submit">Submit</button>
-
</form>
-
<?php } ?>
I added this to my php code, but the textbox is showing up when the page is loaded. How can I fix that so it only shows up after the submit button is clicked? I thought that was what isset was supposed to do. - <?php
-
if(isset($_POST['submit']))
-
{
-
echo '<input name="result" type="text" disabled="disabled" id="result" size="50" maxlength="25" value="Your email was sent successfully."/>';
-
?>
kovik 1,044
Recognized Expert Top Contributor
Firstly, depending on the browser, "submit" may not always be set. I think it was IE that had the problem, but there's a browser that does no set "submit" if the user presses Enter instead of typing the button. It's more reliable to check if the $_POST array is empty or not.
Secondly, you never close the brackets of the if statement.
Thirdly, you haven't shown us much. I don't know what you want us to do with this, knowing nothing at all about your page.
Just follow the example I gave you.
code green 1,726
Recognized Expert Top Contributor
Kovik, I am with you the fact the OP is providing little information.
But you have an irritating habit of correcting minor errors.
I think you meant to place "disabled" inside of the element as an attribute, not outside of it.
I never supply perfect code, unless a ready made function, because I don't have time.
Hence
A simple example using pseudo code
which admittedly was a little bit more, but it was simply an idea, not a ready made solution
kovik 1,044
Recognized Expert Top Contributor
Your solution was wrong and didn't address the problem that the OP was asking. You can't blame me for trying to stop the OP from becoming anymore confused. This is why my first response was a question and not a solution: to make the problem more clear for us all.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Michael Albanese |
last post by:
I am building an application to report on-the-job injuries
and incidents. There are a lot of Date fields, some of
which are optional and can be left blank by the user. I
have allowed Nulls on these fields in my SQL Server DB, as
well as in my stored proc.
The problem is that when I submit this data i get an error
that states "Input not in date format" or a similar
statement when there arevnull date fields.
|
by: AFN |
last post by:
I'm trying to set a submit button to change text and color when clicked.
Like saying "please wait" instead of "submit" and then changing the
background color and text color. All works, except for changing the text
color.
I can set style.background='red' to change the background color to red.
But if I say style.color='green' to change the text color, it does not
change. How do you change the text color on a button when it is clicked?
|
by: Paul M. Frazier, Ph.D. |
last post by:
I am writing a user information update page and I populate the form on
Page_Load with the current values of the user's name, etc. When I
change the text in one of the textbox controls (e.g., change the
user's middle initial from M. to X.) and submit the form, the value
seen for middleinitial.text in the Public Sub that is executed when
the Update button is clicked is the initial value (M.) and not the new
value (X.). Is there something I...
|
by: Steve S |
last post by:
Heres what I want to do...User types into a texbox, clicks a button, the
button saves that text to a file. The problem is that when I click the
submit button, any changes made to the textbox are lost, and it reloads what
was previously there.
Any ideas?
try
{
|
by: buran |
last post by:
Dear ASP.NET Programmers,
I have a question about a script I'm trying to code and invoke when a button
(btnSave) is pressed on the page. This script should only run when a textbox
(txtAD) on the page is left blank. I tried to use a code snippet with the
"return confirm" function but without success. The code should check whether
the textbox is empty or not, and if empty, it should ask the user to
continue and then run the next code. How...
| |
by: hfk0 |
last post by:
Hi,
I'm new to ASP.net, SQL Server and visual studio.net, and I'm having
problem inserting and storing data from a web form to a SQL database.
I created a simple ASP.NET web form, a simple SQL database, a database
connection (using the SQlDataSource Web Control from the Toolbox), and
created the following stored procedure in Visual Studio.Net 2005:
|
by: pd123 |
last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error "
The name 'Peter' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
Where Peter is the value entered in the textbox for firstname (fnameTBox)
I'm sure the problem is something obvious but I...
|
by: Ian Davies |
last post by:
Hi me again,
sorry to be a pain. Ive been struggling with this one all day. Hope you can
understand whats happening. First my script is below. Have a look and I'll
explain at the bottom what it does so far and is failing to do
*******************************
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
include("myconn.php");
|
by: rcoco |
last post by:
Hi,
I want to share this problem. I have a datagrid that will help me
Insert data into sql database. So I made a button On my form so that
when I press the button a new row on datagrid should be created and I
could be able to insert data. But with this code below I've failed
could someone help me and tell me where I'm going wrong:
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |