Jump to content

Sticky Form Functions For Text Fields/Areas


DonGatuna

Recommended Posts

Assist a newbie!

 

I would like to create a function for text input and text area.  I have the following code that generates the text field but it isn't sticky.

 



<?php
            function create_text_field ($label, $name, $value){
                
                echo '<label>'.$label .': </label>';
                
                echo '<input type = "text" name ="'.$name.'" value = "'.$value.'"';


                    if(isset($_POST[$name])&&($_POST[$name]==$value)){


                        echo $_POST[$name];
                    }
                echo '/><br><br>';
            }
  ?>


The data doesn't stick...

 


Please note that the value attribute code is inside <?php?> tags.  


  • I want to create a function that creates text field(s) that is (are) sticky
  • I cannot place a php tag in the value attribute (since it is part of function statements) 

Please comment


 

Edited by mac_gyver
code tags around posted code please
Link to comment
Share on other sites

The overall function should work just fine...as long as you pass the necessary field value as defined in the function.

<?php
function create_text_field ($label, $name, $value){
    echo '<label>' . $label . ': </label>';
    echo '<input type = "text" name ="'.$name.'" value = "'.$value.'"';
    echo '/><br><br>';
}
?>
 
Out of curiosity, what is the goal behind the following lines of code?
if(isset($_POST[$name])&&($_POST[$name]==$value)){
    echo $_POST[$name];
}
 
Are you trying to add an override for $value? If so, the test should probably be executed prior to the input field being displayed.
 
 
Side note: the <label> tag isn't currently connected to the input field. The following documentation provides examples on how to make the connection:
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.