The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Simple PHP Form not working?
masonh928
post Jul 28 2019, 07:15 PM
Post #1


Serious Coder
*****

Group: Members
Posts: 253
Joined: 17-August 13
From: Indiana
Member No.: 19,570



CODE


<?php

if(isset($_POST['PostBtn'])){
    
    echo($_POST['Title']);
    
}

?>

</ul>

</div>

<div class="col-sm-8">

<?php

echo <<<HTML
  <form method="post" action="">
      
      <input type="text" name="Title" class="title-text" placeholder="Give your post a title...">
      
      <br/><br/>
      
      <textarea class="form-control post-text" name="Post" required></textarea>
      
      <br/>
      
      <input type="submit" name="PostBtn" value="Post Now" class="btn btn-primary">
      
  </form>

HTML;

?>




Does anyone know why this code would not work??? I talked to my host and they don't see any reason why this wouldn't work? (I did not worry about sanitization or anything bc this is just for testing purposes) I get absolutely no errors and that's with strict reporting.I refresh the page and the form doesn't even show up? Even emptying cache doesn't work, I had to destroy the session just to get the form to reappear?? Removing the if statement does nothing either

Works fine locally

This post has been edited by masonh928: Jul 28 2019, 07:15 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jul 29 2019, 05:22 AM
Post #2


.
********

Group: WDG Moderators
Posts: 8,239
Joined: 10-August 06
Member No.: 7



Do you use a .php file extension? Does any PHP work online?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jul 29 2019, 10:39 AM
Post #3


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Also, this is invalid:
CODE
HTML;

It should be:
CODE
HTML
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jul 29 2019, 02:37 PM
Post #4


.
********

Group: WDG Moderators
Posts: 8,239
Joined: 10-August 06
Member No.: 7



QUOTE(CharlesEF @ Jul 29 2019, 05:39 PM) *

Also, this is invalid:
CODE
HTML;

It should be:
CODE
HTML


I don't know much about Heredoc syntax, but the manual uses semicolons: https://www.php.net/manual/en/language.type....syntax.heredoc
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jul 29 2019, 05:10 PM
Post #5


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



That has changed since I used heredoc. I remember only a newline was accepted after the closing identifier. I even remember helping other people with this problem on this forum and only a newline was accepted.

Thanks for the update.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jul 29 2019, 05:34 PM
Post #6


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The error must be in code not shown. I put together this test page and it works fine.
CODE
<?php
if(isset($_POST['PostBtn'])){
echo($_POST['Title']);
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
<title>Heredoc Test</title>
</head>
<body>
<div>
<?php
echo <<<HTML
  <form method="post" action="">
   <input type="text" name="Title" class="title-text" placeholder="Give your post a title..." required>
   <br/><br/>
   <textarea class="form-control post-text" name="Post" required></textarea>
   <br/>
   <input type="submit" name="PostBtn" value="Post Now" class="btn btn-primary">
  </form>
HTML;
?>
</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
masonh928
post Jul 29 2019, 05:49 PM
Post #7


Serious Coder
*****

Group: Members
Posts: 253
Joined: 17-August 13
From: Indiana
Member No.: 19,570



Thanks, everyone! So with my experimenting, it wasn't necessarily an error, but rather I guess I needed to put it in the file that included that file ? I think it might be due to my action attribute on the form.

And, in regards to the heredoc syntax: I did use the semicolon as you said was mandated by the manual?? I haven't had any issues with that.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
masonh928
post Jul 30 2019, 01:10 AM
Post #8


Serious Coder
*****

Group: Members
Posts: 253
Joined: 17-August 13
From: Indiana
Member No.: 19,570



https://www.php.net/manual/en/migration73.n...es.core.heredoc

No longer required as of 7.3, but I still use it out of habit lol
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 22nd October 2019 - 10:10 PM