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!
Inserting text into textbox after submit button is clicked
Collapse
X
-
Tags: None
-
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 codeCode:if(isset($_POST['submit'])) echo '<input type="text" value="'.$message.'"/>'; else echo '<input type="text" value=""/>disabled';
Comment
-
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.Comment
-
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.Comment
-
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:Code:<?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:Code:<?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 } ?>
Comment
-
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.
Code:<?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."/>'; ?>
Comment
-
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.Comment
-
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.
HenceA simple example using pseudo codeComment
-
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.Comment
-
This is why my first response was a question and not a solution:Comment
Comment