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.
isbe
  • 233
  • 2
  • 12
  • 1
    Does this answer your question? [Send value of submit button when form gets posted](https://stackoverflow.com/questions/22579616/send-value-of-submit-button-when-form-gets-posted) – caiovisk Jun 07 '21 at 05:18
  • Hi: Thank you for sharing. I tried funtions there if( array_key_exists, but the result is same, shows Empty... – isbe Jun 07 '21 at 05: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 `` – caiovisk Jun 07 '21 at 05: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... – isbe Jun 07 '21 at 05: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... – caiovisk Jun 07 '21 at 05:49
  • @caiovisk: Thank you for your advice. I tried var_dump(isset($_POST['save_progress'])); in functions.php, but it says something went wrong and doesn't save the code. Would you please let me know how to text var_dump? (I'm a newbie, very clumsy... ) – isbe Jun 07 '21 at 21:45
  • Hard to help here as we have no clue on how you are structuring your code, and we unlikelly are going to code it for you... You need to learn more about the Wordpress structure and its fundamentals... See: [New to WordPress](https://wordpress.org/support/article/new-to-wordpress-where-to-start/), [WP Debbuging](https://wordpress.org/support/article/debugging-in-wordpress/), [WP Loading Sequence](https://medium.com/@dendeffe/wordpress-loading-sequence-a-guided-tour-e077c7dbd119) , there is plenty of documentation out there to help you understand what you are doing... – caiovisk Jun 07 '21 at 22:54
  • Hi caiovisk : I see, thank you for your advice. – isbe Jun 08 '21 at 00:45

1 Answers1

0

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

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

Alexandru Burca
  • 427
  • 1
  • 4
  • 15
  • 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. – isbe Jun 07 '21 at 04:47
  • Hi: php code and the
    is in the same page. But, php code is outside of the form => I tired two methods : php code
    /
    php code. Thank you Alexandru
    – isbe Jun 07 '21 at 20:54