-1

I need to store some variable which I can extract from javascript and later need to use on php when submit the form.

So I have created input field on html like

HTML

  <input type="hidden" name="videoname_var" id="videoname_var" method="get"/>

And on init I have set the value of this input from java script

JS

document.getElementById("videoname_var").value = VIDEO_NAME_;

And later on submit, from php I am accessing the value like,

$videoname = $_GET['videoname_var'];

But the value of $videoname is always null,

Anything wrong on this approach?.

Edit:

Here is the from,

<form id=form_id enctype="multipart/form-data" encoding='multipart/form-data' method='post' >
 <input class=" button1" type="submit" name="Submit" value="Upload">
 <input type="hidden" name="videoname_var" id="videoname_var" />
</form>

And I am setting the value from java script $(document).ready() like

document.getElementById("videoname_var").value = VIDEO_NAME_;

And at on submit button click

This php was executing

if (isset($_FILES['file']))
{
 $videoname = $_GET['videoname_var'];
}
CodeDezk
  • 1,230
  • 1
  • 12
  • 40

2 Answers2

1

this for form not input

method="get"

like this

<form method="get" action="">
  <input type="hidden" value="videoname_var value" name="videoname_var" id="videoname_var" />
</form>
  • I am unsure why this got downvoted; given the other answer that got upvoted being the same. Not my dv here btw. Edit: the downvote seems to have been retracted. – Funk Forty Niner Mar 13 '17 at 15:17
  • If you're using GET you do not have to set a method because GET is the default method for a form. – Jay Blanchard Mar 13 '17 at 15:17
1

You have to set your form method in the form element <form method="get|post"> but not in any other form's element.

The method attribute of the form element tells the browser how to send form data to a web server:

<form method="get">
...
</form>

Note that get is the default value and appends the form-data to the form's action URL in name/value pairs: URL?name=value&name=value

Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46