August 16, 201214 yr Hi, I'm attempting to put together my first ever PHP form! I have looked through a few tutorials and one thing I'm confused about is that the form posts back to a particular page 'often the page it is contained on'. Examples show the action="index.php" Does this mean that the entire HTML document I am working on (it's a one page site) needs to be .php not .html? Will this have any implications on the rest of my HTML (and jQuery, the site is very jQuery heavy.) Just not sure as I've not really worked much with PHP before!
August 16, 201214 yr You can give your document a .php extension and add php code between your html code. For example: <div id="somediv"> <?php echo "Hello !"; ?> </div> You don't have to change any of the existing code. Edited August 16, 201214 yr by Leonvv
August 16, 201214 yr Author You can give your document a .php extension and add php code between your html code. For example: <div id="somediv"> <?php echo "Hello !"; ?> </div> You don't have to change any of the existing code. I'm not entirely sure how this works :/ In pretty much every tutorial I've read it states action="pageName.php" and suggests that this will be the page that the form will deliver the information through. I only have one page, index.html. Do I need to change this to index.php for the page to be capable of having a PHP contact form?
August 16, 201214 yr You can link the action to the link itself. So if the form is in index.php (change the extension) you can link the action to index.php too. And add the code that proccess the data in the same page.
August 16, 201214 yr php contact forms php self action in contact form you can either have a separate form processor file like <form method="post" action="form-action.php"> or can use self like this <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > Edited August 16, 201214 yr by sash_oo7
August 16, 201214 yr Author You can link the action to the link itself. So if the form is in index.php (change the extension) you can link the action to index.php too. And add the code that proccess the data in the same page. So I do need to change my page from index.html to index.php in order to have this form work, yes? And will this have any drawbacks on the page functionality because it is now a .php not a .html? This is all I'm asking.
August 16, 201214 yr So I do need to change my page from index.html to index.php in order to have this form work, yes? And will this have any drawbacks on the page functionality because it is now a .php not a .html? This is all I'm asking. No it will function exactly the same, but the only difference is that you're able to write php code in the file.
August 16, 201214 yr So I do need to change my page from index.html to index.php in order to have this form work, yes? And will this have any drawbacks on the page functionality because it is now a .php not a .html? This is all I'm asking. thats how its done no problems in having a .php page along with other .html pages
August 16, 201214 yr php contact forms php self action in contact form you can either have a separate form processor file like <form method="post" action="form-action.php"> or can use self like this <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > sigh using $_SERVER['PHP_SELF'] in a form action is a big security risk cause it infact can be altered best thing to do to post back to the current page your on is just put the name of the current page
August 16, 201214 yr sigh using $_SERVER['PHP_SELF'] in a form action is a big security risk cause it infact can be altered best thing to do to post back to the current page your on is just put the name of the current page op is still learning ? so i showed her both ways ?
August 16, 201214 yr op is still learning ? so i showed her both ways ? uh yea rather she is learning or not theres no reason to show her a way that is a potential security risk without alerting her of that risk
August 17, 201214 yr ok u win thread closed mm threads still open though? think u mean case closed? or point made? or maybe just a thank you for pointing that out lol
August 17, 201214 yr You do need to learn some PHP because if a user fills in the form and after submitting the data the same page shows again, you need to ensure that the data is erased from the form or it might get submitted again. It is possible to show tha same page again, possibly substituting the form with a message like "Thanks, your data has been sent".
August 18, 201214 yr uh yea rather she is learning or not theres no reason to show her a way that is a potential security risk without alerting her of that risk I'm struggling to see the security risk here. It can only be changed by a user on their own PC - so the 'hacker' could send the form to one of his own scripts? Brilliant. He can do that using web inspector on any HTML form on the whole Internet.
August 20, 201214 yr sigh using $_SERVER['PHP_SELF'] in a form action is a big security risk cause it infact can be altered best thing to do to post back to the current page your on is just put the name of the current page Leaving the action attribute blank is so much more effortless than typing all of that junk. :v
August 20, 201214 yr Leaving the action attribute blank is so much more effortless than typing all of that junk. :v nope it dont
August 20, 201214 yr It's just one of those overly paranoid "popular" security points a lot of people on this forum quote a lot. I tend to just ignore it tbh. thanks for ur input still pointing it out though Edited August 20, 201214 yr by webdesigner93
August 20, 201214 yr I'm struggling to see the security risk here. It can only be changed by a user on their own PC - so the 'hacker' could send the form to one of his own scripts? Brilliant. He can do that using web inspector on any HTML form on the whole Internet. yea im aware but like i said to rallport im still gonna point it out
Create an account or sign in to comment