Delete text in textbox using PHP

Is there a way to remove text from a text field using the submit button?

I do not want to remove text from all form fields.

And I do not want to delete the text 'onclick' for the element.

I need code to clear a text box to start from within a block.

for instance

<input name="text" value="submit" />
<input type="sumbit"/>

<?php 
   if($_POST['submit'] == "submit")
{
  //clear text box with name "text"
}
?>

Thank you for your help!

+3
source share
5 answers

You can do this in two ways:

  • using onclick handler of submit button in javascript

  • using php

    if (count ($ _ POST)> 0) {$ _REQUEST ['text'] = $ _GET ['text'] = $ _POST ['text'] = ''; }

+3
source
onclick="document.getElementById('mytextbox').value = '';"
+2
source

... [javascript], onclick, PHP .

@webbiedave: " onclick ?", , , , PHP .

, , . . PHP ( ), :

<?php 

$textbox_value = 'submit';

if(isset($_POST['clear']))
{
    $textbox_value = '';
}

?>
<input name="text" value="<?php ech $textbox_value; ?>" />
<input type="sumbmit" name="clear"/>

- javascript :

<input name="text" value="some value" id="someUniqueIDYouMakeUp" />
<input type="sumbmit" name="clear" onclick="document.getElementById('someUniqueIDYouMakeUp').value='';return false;" />
+1

, PHP.

PHP :

:

<?php 
   if($_POST['submit'] == "submit") {
   //clear text box with name "text"
   echo '<input name="text" value="" />';
  }
  else {
   echo '<input name="text" value="submit" />';
  }
?>

"" . , .

0

, . PHP - . , , PHP- .

, ... , , ... .

, . .

JavaScript.

0

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


All Articles