9

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

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

Now the button shows the value of $fields + 1. Actually what I want is the button to show something else (like add new field). Just adding text between the <input>...</input> tags does not help. The text just appears right of the button.

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

  • Possible duplicate of [HTML Submit-button: Different value / button-text?](http://stackoverflow.com/questions/4171664/html-submit-button-different-value-button-text) – Organic Advocate Feb 02 '16 at 22:58

3 Answers3

10

You can use an hidden input to store the value count, 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 ?>" />
Zuul
  • 16,217
  • 6
  • 61
  • 88
  • 2
    may not work when you have multiple submit fields, and need different value for each internally (not visible), with different names for each externally (visible) – Dennis Nov 25 '14 at 23:27
9

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

Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
jelle foks
  • 751
  • 6
  • 8
3

You Can use the hidden field to store or post the $fields+1 value:

<input type="hidden" name="fields" value="<?php echo $fields+1 ?>" />
<input type="submit" name="submitter" value="Send" />
Suresh kumar
  • 2,002
  • 1
  • 19
  • 28
Akarun
  • 3,220
  • 2
  • 24
  • 25