469,328 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Inserting text into textbox after submit button is clicked

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!
Dec 23 '09 #1
11 8722
kovik
1,044 Expert 1GB
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?
Dec 23 '09 #2
code green
1,726 Expert 1GB
A simple example using pseudo code
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['submit']))
  2.     echo '<input type="text" value="'.$message.'"/>';
  3. else
  4.   echo '<input type="text" value=""/>disabled';
Dec 23 '09 #3
kovik
1,044 Expert 1GB
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.
Dec 23 '09 #4
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.
Dec 23 '09 #5
kovik
1,044 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $success = false;
  3. $errors = array();
  4.  
  5. if (!empty($_POST)) {  // Form has been submitted
  6.   // Validate all form elements and add errors
  7.   //   to the $errors array when invalid
  8.   if (empty($_POST['name'])) {
  9.     $errors[] = 'Name must be filled.';
  10.   }
  11.  
  12.   // Perform the operation if the form is valid
  13.   if (empty($errors)) {
  14.     // Do stuff here
  15.     $success = true;  // Set $success = true if successful
  16.   }
  17. }
  18. ?>

View:
Expand|Select|Wrap|Line Numbers
  1. <?php if ($success) { ?>
  2. <p>Successful!</p>
  3. <?php } else { ?>
  4. <form method="post" action="#">
  5.   <?php if (!empty($errors)) { ?>
  6.   <ul>
  7.     <?php foreach ($errors as $error) { ?>
  8.     <li><?php echo $error; ?></li>
  9.     <?php } ?>
  10.   </ul>
  11.   <?php } ?>
  12.   <input type="text" name="name" />
  13.   <button type="submit">Submit</button>
  14. </form>
  15. <?php } ?>
Dec 24 '09 #6
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['submit']))
  3. {
  4.     echo '<input name="result" type="text" disabled="disabled" id="result" size="50" maxlength="25" value="Your email was sent successfully."/>';
  5. ?>
Dec 24 '09 #7
kovik
1,044 Expert 1GB
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.
Dec 24 '09 #8
code green
1,726 Expert 1GB
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
Dec 24 '09 #9
kovik
1,044 Expert 1GB
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.
Dec 24 '09 #10
code green
1,726 Expert 1GB
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
Dec 24 '09 #11
kovik
1,044 Expert 1GB
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...
Dec 24 '09 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Michael Albanese | last post: by
1 post views Thread by Paul M. Frazier, Ph.D. | last post: by
5 posts views Thread by Steve S | last post: by
6 posts views Thread by Ian Davies | last post: by
3 posts views Thread by rcoco | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.