Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP form posting back to current page

Featured Replies

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!

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 by Leonvv

  • 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?

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.

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 by sash_oo7

  • 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.

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.

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 :)

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 ;)

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 ?

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

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".

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.

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

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 by webdesigner93

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.