submitting $_POST data to a script without using a form

Permabanned
Joined
25 Oct 2004
Posts
9,078
As per title, is it possible to submit form data via $_POST to a script without using the forms submit button.

IE

If i have a security feature on a form that uses PHP_SELF as its action, does some magic behind the scenes and then submits the rest of the $_POST data to a phpmail script providing the security feature returns a "true".

Any help appreciated :D
 
How do you know when it is to start the submission if there is no user action? You could probably emulate the submit buttons activity so its not actually pressed..
 
What are you trying to achieve? There's always more than 1 way to skin a cat.
 
Its not without user action so to speak, basically I have a form which people can fill out and part of the form has security information.

If that security information is invalid nothing happens, all they get is a "doh you forgot to fill in the security information" without refreshing the form/page.

If they get it right, i want to resubmit the form to my mail script, which requires variables are passed using $_POST.

So what im looking for is a way to resubmit data after a user has already clicked submit once.
 
No point resubmitting, you've already got the data required, why send it back to the user, then have it automatically sent back to the server again? :)
 
Its not submitting to the user.

What its basically doing is

user enters security information -> user clicks submit -> using PHP_SELF the form self validates -> security code is correct -> $_POST data is sent to phpmailer script

As the form itself has action="<?php echo $_SERVER['PHP_SELF']; ?>" instead of bypassing the security and just using action="phpmailer.php"
 
You can easily submit a form using JavaScript even without using things like JQuery. You still need to have a <form> though.

I don't understand what you mean here:

using PHP_SELF the form self validates
 
Its not submitting to the user.

What its basically doing is

user enters security information -> user clicks submit -> using PHP_SELF the form self validates -> security code is correct -> $_POST data is sent to phpmailer script

As the form itself has action="<?php echo $_SERVER['PHP_SELF']; ?>" instead of bypassing the security and just using action="phpmailer.php"
Let's start again..

Why do you need to have a form auto-post?
 
Its his security thats messing it all up...

Why not
1) Have user enter data
2) Convert posted data to session data, check session data for validation/security
3) Send user back to form (which populates from session data to avoid reinput bar the incorrect security entry)
4) Repost and reset the session data..

I'd get away from PHP_SELF.. http://www.mc2design.com/blog/php_self-safe-alternatives#hide
 
Last edited:
Its the security that is messing it up indeed, the form has full validation etc but some muppet decided to use a charity website to bombard our server with spam emails so I had to implement additional security, one of those features is captcha, unfortunately because of how the php email script is set up it requires data be passed to it using $_POST.

Now i can quiet easily implement the security without needing to check its ok before submitting the form, but by doing that if the code is wrong all previous form data is lost and user has to input it all again.

What im attempting to do is, when the user clicks on submit it validates all form data and providing the security questions are correct, submits it all to the php mail script using $_POST so that it can continue on with emailing the form data to who ever. If the code is incorrect, well the data is still there for them, so they only need to change the security codes.
 
So whats stopping you from using sessions to pass the data back into to the form so they only have to input the security code properly before it validates it all again via POST?

Users could then modify other answers if they need to..
 
Back
Top Bottom