Get a HTML input value out of a file which is located in a subfolder?
I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.
- php-File (shortcode-concerts.php)
- classes-Folder
- HTML-File (mainLook.html)
The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.
However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?
The modal window in the /classes/mainLook.html File:
<div id="modal_createconcert" class="modal">
<div class="modal-content">
Concert: <input type="text" id="input_concert"/>
Date: <input type="date" id="input_date"/>
Time: <input type="time" id="input_time"/>
Place: <select id="combo_place"></select>
<button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
</div>
</div>
The php-File:
<?php
function shotcode_concerts(){
include("classes/mainLook.html");
}
if($_GET['button1']){fun1();}
function fun1()
{
?>
<script type="text/javascript">
var concert = document.getElementById('input_concert');
alert(concert);
</script>
<?php
}
?>
javascript php jquery html wordpress
add a comment |
I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.
- php-File (shortcode-concerts.php)
- classes-Folder
- HTML-File (mainLook.html)
The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.
However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?
The modal window in the /classes/mainLook.html File:
<div id="modal_createconcert" class="modal">
<div class="modal-content">
Concert: <input type="text" id="input_concert"/>
Date: <input type="date" id="input_date"/>
Time: <input type="time" id="input_time"/>
Place: <select id="combo_place"></select>
<button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
</div>
</div>
The php-File:
<?php
function shotcode_concerts(){
include("classes/mainLook.html");
}
if($_GET['button1']){fun1();}
function fun1()
{
?>
<script type="text/javascript">
var concert = document.getElementById('input_concert');
alert(concert);
</script>
<?php
}
?>
javascript php jquery html wordpress
add a comment |
I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.
- php-File (shortcode-concerts.php)
- classes-Folder
- HTML-File (mainLook.html)
The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.
However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?
The modal window in the /classes/mainLook.html File:
<div id="modal_createconcert" class="modal">
<div class="modal-content">
Concert: <input type="text" id="input_concert"/>
Date: <input type="date" id="input_date"/>
Time: <input type="time" id="input_time"/>
Place: <select id="combo_place"></select>
<button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
</div>
</div>
The php-File:
<?php
function shotcode_concerts(){
include("classes/mainLook.html");
}
if($_GET['button1']){fun1();}
function fun1()
{
?>
<script type="text/javascript">
var concert = document.getElementById('input_concert');
alert(concert);
</script>
<?php
}
?>
javascript php jquery html wordpress
I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.
- php-File (shortcode-concerts.php)
- classes-Folder
- HTML-File (mainLook.html)
The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.
However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?
The modal window in the /classes/mainLook.html File:
<div id="modal_createconcert" class="modal">
<div class="modal-content">
Concert: <input type="text" id="input_concert"/>
Date: <input type="date" id="input_date"/>
Time: <input type="time" id="input_time"/>
Place: <select id="combo_place"></select>
<button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
</div>
</div>
The php-File:
<?php
function shotcode_concerts(){
include("classes/mainLook.html");
}
if($_GET['button1']){fun1();}
function fun1()
{
?>
<script type="text/javascript">
var concert = document.getElementById('input_concert');
alert(concert);
</script>
<?php
}
?>
javascript php jquery html wordpress
javascript php jquery html wordpress
edited Dec 27 '18 at 20:14
asked Dec 27 '18 at 20:01
sunnys
33
33
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).
mainLook.html
<div id="modal_createconcert" class="modal">
<div class="modal-content">
<form action="some/location/file.php" method="post">
Concert: <input type="text" name="input_concert"/>
Date: <input type="date" name="input_date"/>
Time: <input type="time" name="input_time"/>
Place: <select name="combo_place"></select>
<button class="button" type="submit" id="button_save">Save!</button>
</form>
</div>
</div>
file.php
<?php
include("classes/mainLook.html");
function fun1($var_val)
{
?>
<script type="text/javascript">
alert("<?php echo $var_val; ?>");
</script>
<?php
}
if $_SERVER['REQUEST_METHOD'] == 'POST' {
fun1($_POST['input_concert'])
}
Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.
I hope it helps in something.
add a comment |
The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950268%2fget-a-html-input-value-out-of-a-file-which-is-located-in-a-subfolder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).
mainLook.html
<div id="modal_createconcert" class="modal">
<div class="modal-content">
<form action="some/location/file.php" method="post">
Concert: <input type="text" name="input_concert"/>
Date: <input type="date" name="input_date"/>
Time: <input type="time" name="input_time"/>
Place: <select name="combo_place"></select>
<button class="button" type="submit" id="button_save">Save!</button>
</form>
</div>
</div>
file.php
<?php
include("classes/mainLook.html");
function fun1($var_val)
{
?>
<script type="text/javascript">
alert("<?php echo $var_val; ?>");
</script>
<?php
}
if $_SERVER['REQUEST_METHOD'] == 'POST' {
fun1($_POST['input_concert'])
}
Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.
I hope it helps in something.
add a comment |
In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).
mainLook.html
<div id="modal_createconcert" class="modal">
<div class="modal-content">
<form action="some/location/file.php" method="post">
Concert: <input type="text" name="input_concert"/>
Date: <input type="date" name="input_date"/>
Time: <input type="time" name="input_time"/>
Place: <select name="combo_place"></select>
<button class="button" type="submit" id="button_save">Save!</button>
</form>
</div>
</div>
file.php
<?php
include("classes/mainLook.html");
function fun1($var_val)
{
?>
<script type="text/javascript">
alert("<?php echo $var_val; ?>");
</script>
<?php
}
if $_SERVER['REQUEST_METHOD'] == 'POST' {
fun1($_POST['input_concert'])
}
Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.
I hope it helps in something.
add a comment |
In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).
mainLook.html
<div id="modal_createconcert" class="modal">
<div class="modal-content">
<form action="some/location/file.php" method="post">
Concert: <input type="text" name="input_concert"/>
Date: <input type="date" name="input_date"/>
Time: <input type="time" name="input_time"/>
Place: <select name="combo_place"></select>
<button class="button" type="submit" id="button_save">Save!</button>
</form>
</div>
</div>
file.php
<?php
include("classes/mainLook.html");
function fun1($var_val)
{
?>
<script type="text/javascript">
alert("<?php echo $var_val; ?>");
</script>
<?php
}
if $_SERVER['REQUEST_METHOD'] == 'POST' {
fun1($_POST['input_concert'])
}
Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.
I hope it helps in something.
In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).
mainLook.html
<div id="modal_createconcert" class="modal">
<div class="modal-content">
<form action="some/location/file.php" method="post">
Concert: <input type="text" name="input_concert"/>
Date: <input type="date" name="input_date"/>
Time: <input type="time" name="input_time"/>
Place: <select name="combo_place"></select>
<button class="button" type="submit" id="button_save">Save!</button>
</form>
</div>
</div>
file.php
<?php
include("classes/mainLook.html");
function fun1($var_val)
{
?>
<script type="text/javascript">
alert("<?php echo $var_val; ?>");
</script>
<?php
}
if $_SERVER['REQUEST_METHOD'] == 'POST' {
fun1($_POST['input_concert'])
}
Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.
I hope it helps in something.
answered Dec 27 '18 at 22:45
MarcosAM
262
262
add a comment |
add a comment |
The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.
add a comment |
The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.
add a comment |
The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.
The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.
answered Dec 27 '18 at 20:47
compt
5715
5715
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950268%2fget-a-html-input-value-out-of-a-file-which-is-located-in-a-subfolder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown