Submit buttons: button text is different from the value

I am writing a search form in PHP. I want the user to be able to add search fields using the following submit button:

<input type="submit" name="fields" value="<?php echo $fields+1 ?>" /> 

Now the button shows the value of $fields + 1 . Actually, I want the button to display something else (for example, add a new field). Just adding text between the <input>...</input> does not help. The text is simply displayed to the right of the button.

How to change the text on a button and pass the value of $fields + 1 to GET / POST?

+6
source share
3 answers

You can use hidden input to store the value, it will be available after GET / POST:

 <input type="submit" name="fields" value="add new field" /> <input type="hidden" name="fieldsCount" value="<?php echo $fields+1 ?>" /> 
+6
source

You can use the button element:

 <button type="submit" name="seven" value="7">Push Me</button> 

Refs: http://www.w3schools.com/tags/att_button_type.asp

+5
source

You can use a hidden field to store or send the value of $fields+1 :

 <input type="hidden" name="fields" value="<?php echo $fields+1 ?>" /> <input type="submit" name="submitter" value="Send" /> 
+2
source

Source: https://habr.com/ru/post/917956/


All Articles