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 9138
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?
A simple example using pseudo code - if(isset($_POST['submit']))
-
echo '<input type="text" value="'.$message.'"/>';
-
else
-
echo '<input type="text" value=""/>disabled';
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.
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."/>';
-
?>
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.
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
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.
This is why my first response was a question and not a solution:
And that is why my first response was a pseudo-code example and not a solution
Why are you defending it? You either make an input box with a message or one with disabled written next to it. At least correct it to fit the post...
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...
|
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...
|
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.,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |