Link to home
Start Free TrialLog in
Avatar of Kenny darcy
Kenny darcy

asked on

PHP Echo with auto submit

Hello,

I have the following below and insert form.

     echo "<form action=\"index.php\" method=\"post\" id=\"plop1\">";
      echo "<input name=\"ding9\" type=\"hidden\" id=\"ding9\" value=\"1\" />";
      echo "<script type=\"text/javascript\">document.getElementById('plop1').submit()</script>";
      echo "</form>";
      $_REQUEST        = array(); // clear form values

All works well, but a quick question........ is this form of submit safe and the best way, I say this as when I have tested it, the page goes white for a moment then redir to where I want with the hidden value. It seems maybe the page is kinda refreshing.

all in all how you would submit passing the form variable as safe as possible and auto submitted.


regards

K
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Why would it be any less safe?

From your code it appears you are wanting to auto submit a form - question - what is it you are trying to achieve. This method is often used in shopping carts that have an external provider that handles the transaction - create a form with all the data you need to send and auto submit it - however in your case you are submitting to index.php

If you explain what it is you are trying to achieve we can recommend best practice on how to do this.

There is nothing wrong with what you have - but to properly answer the question you need to provide more context.
Hello,

POST method is a secure way of submitting the form, as per your page is not refreshing, it take couple of seconds to submit the form to index.php. Are you only submitting only one hidden value or do you have more form elements in original form?
Avatar of Kenny darcy
Kenny darcy

ASKER

thank you both,

what am I trying to achieve....

I have an area that allows a user to update profile, on form submit I want the user to be taken to the index and on the index where I have an if else "thank you you have updated your details" to do this I need to pass a value thus this is what I am doing.

i am submitting only one hiddenfield

cheers

k
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HTML forms and PHP script interactions are covered in the introductory tutorial:
http://php.net/manual/en/tutorial.php

If you're new to PHP and want to learn the language, this article can help.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
thank you very much, it is so good to have others thoughts on this, you know how it is when your coding at home and sometimes lack confidence if something is right and wrong. I am grateful for both of your advice. cheers
You are welcome.