I know this might be a beginners question, but what exactly goes in the action of a form and what does it do? I mean like this...
<form id="feedback" method="post" action="">
I am confused as to if I need to include anything there. Is that where the mail func goes or something.
action
Started by Bouzy210, Jul 20 2007 11:33 AM
5 replies to this topic
#1
Posted 20 July 2007 - 11:33 AM
#2
Posted 20 July 2007 - 11:39 AM
a file or the path to a file that can handle POST requests should go into the action element of a form
HTML can not actually DO anything with a form, it simply makes the form...Another language (usually javascript or PHP) takes the form data and parses the results...but how does the HTML know what php or javascript file to select? That's where the action part comes in.. for example:
<form action="post_news.php">
.. form data here
</form>
Now, after the user hits the submit button your form, the page will go to post_news.php where the form data will be parsed according to the contents of post_news.php
HTML can not actually DO anything with a form, it simply makes the form...Another language (usually javascript or PHP) takes the form data and parses the results...but how does the HTML know what php or javascript file to select? That's where the action part comes in.. for example:
<form action="post_news.php">
.. form data here
</form>
Now, after the user hits the submit button your form, the page will go to post_news.php where the form data will be parsed according to the contents of post_news.php
#3
Posted 20 July 2007 - 11:49 AM
Ohhh. I was putting my php in the same page as my form. Are you saying this is incorrect? I had like my
in the same file as my html form stuff. should I have all this things like it in an include file that I put the path in the action? If that is correct does the mail() function code and stuff go in the same php file as the other stuff and it all is directed to through action?
<?php
if ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message. Please check to make sure you filled out all the required entries.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p><strong>Your message has been sent. Thank you.</strong></p>
<?php } ?>
in the same file as my html form stuff. should I have all this things like it in an include file that I put the path in the action? If that is correct does the mail() function code and stuff go in the same php file as the other stuff and it all is directed to through action?
#4
Posted 20 July 2007 - 02:51 PM
No no, you can keep it in 1 file. As such:
<?php
if(isset($_POST)){
// Check for input
if(isset($_POST['subject']) && isset($_POST['message'])){
//get the Boolean from mail();
if(mail("youradress@server.com",$_POST['subject'],$_POST['message'])){
print "Mail sent succesfully.";
}else{
print "An error occurred";
}
}else{
print "No input was given";
}
}else{
//if $_POST is not set, the form is shown
print "<form method='post' action=''>";
print "..... Rest of form...";
}
?>
#5
Posted 20 July 2007 - 04:17 PM
Ok I guess its working better now, but how do you prevent errors from showing up in the first place? like if a file extension or something is missing is there a way to just turn off errs so an ugly big error wont show up and ruin my layout? I mean it would be kind of imbarising if it failed to connect to mail server then showed a big error.
Edited by Bouzy210, 20 July 2007 - 04:20 PM.
#6
Posted 20 July 2007 - 07:22 PM
That's where custom error handling comes in.
set_error_handler()
Or simply turn them off (NOT a very wise idea...).
set_error_handler()
Or simply turn them off (NOT a very wise idea...).
error_reporting(0);
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
