MyBB Community Forums

Full Version: Form Submit Button Not Executing PHP Code in usercp.php?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The PHP code below just doesn't work for usercp.php.

The html form action="usercp.php" overrides the below PHP code, no matter what the PHP code is.


<form action="usercp.php" method="post">
	<input type="submit" class="button" name="editprofile" value="Edit Profile" />
</form>

So when I click on the Edit Profile button (a button I made), it just redirects to action="usercp.php", instead of executing the PHP code below, showing "it works".

I tried action="" and it WORKS, but with a distorted page. Why does action="usercp.php" override the PHP code below?


global $mybb;

if(isset($mybb->input['editprofile'])) {
	echo 'it works';
	die();
	}

What could be the problem?

Could someone else try copying this code on usercp.php and see if exactly the same thing happens?

I tried this on a blank test page on XAMPP, and it works, so why doesn't it work on MyBB?
With a submit you finish a form, and the action performed by that is always specified in the action that is defined in the form tag, not in the submit button. The name you give in the submit is passed as some type of argument in the $mybb->input array, but the action remains the same.

Where did you place this PHP code?
For testing purposes only I put the PHP code in the usercp.php template using the PHP in templates plugin.

That's not the point. Whatever PHP code I put to be executed when clicking the button, it is not executed in MyBB. It just redirects to usercp.php (which I want it to!), but I need the code to be executed too. If I would put a DB query that needed to be executed, it would just redirect to usercp.php, without executing any of the code.

The point being: None of the PHP code is executed. Can you please try putting a test form in any usercp.php template, and see if it works? It won't work.

MyBB seems to be the problem. I tried this exact code on a random test.php page using if(isset($_POST['editprofile'])), and it worked fine.
I'm not sure whether I understand this completely, I never tried the PHP in templates plugin, and for the time being I don't need it.
But realize that the PHP in the template is run when the template is being evaluated. When you press a submit button, the PHP in the module that is set in the action of the form is executed. As I read it you want PHP in the template being executed when you press the submit button, and that is not what will happen.
I have used other PHP code in templates for testing, and it worked fine.

Do you have a solution then, for making forms work with PHP properly?

EDIT: Ok. So PHP in templates doesn't work too well. I tried the PHP code in a core file, and it worked fine Smile