0

I need to know if 'input submit button' is clicked.
I tried following php codes, and clicked a save_progress button, but it echos 'EMPTY'.
Would you please let me know how to know it the button is clicked or get the value of the button?

Existing code (submit page):

<form class="acfef-form -submit" action="" method="post" autocomplete="disableacf" novalidate="novalidate" data-widget="fc8926d" id="acf-form-fc7226d18999" enctype="multipart/form-data"> 
     <div class="1"></div>
     <div class="2"></div>
     <div class="3">
          <div class="3-1"><input class="acfef-submit-button" type="submit" value="Save" data-state="publish"></div>
     </div>
     <div class="4"><input class="save-progress-button" name="save_progress" type="submit" data-state="revision" value="Revision"></div>

</form>

php codes I tried in the submit page:
if(isset($_POST['save_progress'])) {
    echo 'NOT EMPTY ';
    }else{
    echo 'EMPTY ';
}

if (empty($_POST['save_progress'])){

if( array_key_exists( 'save_progress', $_POST ) ){

Thank you.
8
  • 1
    Does this answer your question? Send value of submit button when form gets posted Commented Jun 7, 2021 at 5:18
  • Hi: Thank you for sharing. I tried funtions there if( array_key_exists, but the result is same, shows Empty... Commented Jun 7, 2021 at 5:29
  • Sorry mate, but that answer there is the right for your question... it says "The button names are not submit, so the php $_POST['submit'] value is not set. As in isset($_POST['submit']) evaluates to false." ... so you should put a value on your input submit... like this <input class="save-progress-button" name="save_progress" type="submit" value="submitted"> Commented Jun 7, 2021 at 5:35
  • Hi caiovisk: The input actually has value, I missed the update. I'm sorry, my bad. I updated them just now. It still shows Empty with value... Commented Jun 7, 2021 at 5:40
  • It should work then, just tested here... So, you need to start debugging your code then... there is plenty of resource on Google... My tip would be to start putting the var_dump($_POST); before the if statement, see if you getting that post variable, and so on... Commented Jun 7, 2021 at 5:49

1 Answer 1

0

Specify method="post" like <form class="acfef-form" method="post">

Also you should place your PHP code into a WP Hook, like init.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi: Thank you for your adivce. The form has method, I updated them (sorry, my bad, I didn't write all of them when I ask questions). I'm a newbie, not sure what deos 'PHP code into a WP Hook, like init' mean. Would you please let me know how to implement them? Thank you.
Hi: php code and the <form> is in the same page. But, php code is outside of the form => I tired two methods : php code <form></form> / <form></form> php code. Thank you Alexandru

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.