Jump to content
Paul-D

Can't read value of text box

Recommended Posts

Posted (edited)

I have a text box on page 1 that has a unique changing value using

 

$Comment_Name = dechex(time());

$_SESSION['COMMENT_NAME'] = $Comment_Name;

// Lines 42/43

            Comment    
            <input type="text" maxlength="32" size="42" name= "<?=$Comment_Name?>"; value="<?=$SE_Comment?>">&nbsp;&nbsp;Max 32 Characters

 

As the name of the text box is stored in a session variable then it should be a simple mater of retrieving the value on page 2.

/****************************/ 

$CommentID = $_SESSION['COMMENT_NAME'];

if($direction  == "Add record")

{

                $Comment_Name = $_SESSION['COMMENT_NAME'];

                $_SESSION['DE_MyReason'] = $_POST['Reason']; // Keep the default regardless

                $_SESSION['DE_Money_In'] = $_POST['MoneyIn'];

                $_SESSION['DE_Money_Out'] = $_POST['MoneyOut'];

                $_SESSION["DE_DD_Entry"] = $_POST['DD_Entry'];

                $_SESSION["DE_MM_Entry"] = $_POST['MM_Entry'];

 

                $_SESSION["DE_Comment"] = $_POST[$CommentID];  /* This should retreve the posted value */

 

Any help on this please?

Edited by Paul-D

Share this post


Link to post
Share on other sites

First, please use the code icon (<>) to insert you code and select PHP. If you say the input value is stored in the session variable, where is the code that does that? It looks like you omitted too much of the code we need to see.

Share this post


Link to post
Share on other sites

YOu really can't be using a variable value as the name attribute of an html tag.  Simply call your comment input "comment" and reference that in the $_POST or $_GET array when you receive the submitted data.  The use of SESSION for this is kinda screwy!

Share this post


Link to post
Share on other sites

Are you calling "session_start()" at the beginning of the second page?

 

47 minutes ago, ginerjm said:

The use of SESSION for this is kinda screwy!

+1

Share this post


Link to post
Share on other sites

I'd like to see your entire form html so I can see how you named all of your other input elements and why you chose one of them for the mystery name.

Share this post


Link to post
Share on other sites
Posted (edited)

ginerjm seems to have done this. What I have been doing is using a variable into the name of the text box. This has worked before. I use dechex(time()) and use this as the name. The reason is that some of the older web pages got screwed up by a web browser trying to artificial intelligent and complete what I am entering based on the name of the text box. I then store the name in a session variable so the update page can use it for the name of the text box. 

 

Hope this makes

$Comment_Name = dechex(time());
$_SESSION['COMMENT_NAME'] = $Comment_Name;

and for the text box

<input type="text" maxlength="32" size="42" name= "<?=$Comment_Name?>"; value="<?=$SE_Comment?>">

This has worked before but can't work out how I did it.

Edited by Paul-D

Share this post


Link to post
Share on other sites

Have no idea what your last post was trying to say.  Does it even make sense to you?

 

You are doing something that I doubt very many others even consider.  When writing forms and inputs one chooses a name attribute value for each input field and then uses that value to retrieve it once the user submits the form and its data.  To have a variable name value means a headache for your receiving script which has to figure out what to call that specific field when having simple static values is so much easier.   As for a hack - if the name of an input is un-knowable then you won't get that piece of data from the submit and so your script should properly abort its process and send the user a message to that effect.

I have made my case.  Good bye.

Share this post


Link to post
Share on other sites
1 hour ago, Paul-D said:

I use dechex(time()) and use this as the name. The reason is that some of the older web pages got screwed up by a web browser trying to artificial intelligent and complete what I am entering based on the name of the text box. I then store the name in a session variable so the update page can use it for the name of the text box.

Unless I'm reading that wrong, it seems to me that turning off autocomplete would be a heck of a lot easier all around.

Share this post


Link to post
Share on other sites

Some page was messed up because someone used artificial intelligence on it?  Is that what you are trying to say?

The assignment of an input's name attribute is solely controlled by the guy writing the script and therefore the form/html.  And AS I SAID if the script doesn't find that name in the POST array input then it is quite apparent that someone DID do something and your script should not process the whole thing!

Share this post


Link to post
Share on other sites
Posted (edited)

No that doesn't always work. If websites use Name="Name" for an input form which they do. You can get auto complete to work the wrong way. I don't want to turn off auto complete.

 

As for 

To have a variable name value means a headache for your receiving script which has to figure out what to call that specific field when having simple static values is so much easier.

 

    $Comment_Name = $_SESSION['COMMENT_NAME'];
    $Comment = $_POST[$Comment_Name];

 

Edited by Paul-D

Share this post


Link to post
Share on other sites
Posted (edited)

NO that doesn't always work?  A coder writes the code that holds that name - how the h... does it "not work"?  Please elaborate.

You are the first person whom I have seen using this convoluted naming convention. 

I have been reading these forums  and coding PHP/HTML for about 6 years now.  What does that tell you about your statement that it doesn't always work?

And - autcomplete is an html feature (not php) that helps to finish providing the input value of the tag and has absolutely nothing to do with the name attribute clause.  The assigned name will always be the assigned name from the time that the php script generates it, sends it, and receives it back unless someone hacks the page (and perhaps other input tags as well) and sends it back to your script corrupted.  Good security procedures advise you to check for valid input "names" and their expected values.  An altered input name attribute as I have already said is a sign that you should not use the inputs at that point.

Edited by ginerjm

Share this post


Link to post
Share on other sites

I am completely lost in this thread. What is the OP trying to accomplish?

Share this post


Link to post
Share on other sites
On 6/24/2019 at 5:23 AM, Paul-D said:

As the name of the text box is stored in a session variable then it should be a simple mater of retrieving the value on page 2.

Did you figure out why the SESSION variable wasn't working? As mentioned in Barand's post, session_start() needs to be called at the beginning of the script(s), before using $_SESSION.

 

1 hour ago, Paul-D said:

If websites use Name="Name" for an input form which they do. You can get auto complete to work the wrong way.

Could you provide a little more information by what you mean by the "wrong way"? For example, let's say you have a "name" field where you want the person's name. And another website has a "name" field that asking for a product name. Well, if someone happens to fill that form out before yours, autocomplete tries to add the product name into your field. Is that the type of scenario we're talking about here?

 

1 hour ago, Paul-D said:

I don't want to turn off auto complete.

Isn't that basically what you're doing with the dynamic naming idea? The advantage with turning off auto complete is that it makes the code much simpler to manage in the long run.

Just to clarify, the link maxxd provided shows how to tell the browser (for all users) that auto complete shouldn't be used. It's not the local setting that only turn auto complete off for you. Maxxd's link also shows that auto complete can be disabled for an entire for or a single input field. So there is some flexibility.

Share this post


Link to post
Share on other sites

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.