MyBB Community Forums

Full Version: How to bypass form action="action.php" with PHP?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basically I don't want the page to redirect to "action.php" this one time.

I need it to stay on the same page. I know about action="" but I still need it to redirect, just not this one time.

Is there a PHP function that makes the redirect to stay on the same page, the same functionality as action=""?
That's nothing you can do with php as php is a server side language and so a redirect (or another call) needs to be made so php is executed. You can do something with JavaScript as it's a client side language.

Something like (note: will likely not work):
<form action="" onsubmit="return false;">
</form>

There are different event handlers where you can call ".preventDefault()" and such things. You need to look which one is the best, I'm not that familiar with JS Wink
I assume you are trying to redirect to the same page regardless of the outcome status (error, success, preview, etc)?

Lets say the following:
if($mybb->get('action') == 'foo')
{
	$success = array();
	if($mybb->request_method == 'post')
	{
		$success = 'The form was executed successfully.';
	}

	$success or $success = '';

	echo $success;
	echo $form;
}

Now have the form pointing to action=foo, the first time the user visits the page it will be presented with only the $form and $success emptied. Once the user summits the form, $success will be filled with a message.

Sorry if I don't explain myself well but I think this is what you are trying to achieve.