Basic PHP form stuff

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Georgezx9
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Mar 31, 2014 1:15 pm

Basic PHP form stuff

Postby Georgezx9 » Mon Mar 31, 2014 1:29 pm

Hi all newbie starting off here and HELP!

I have a form that I want someone to type text into, this will later be saved to an SQL DB.

I also have a date field, that I want to come up as dd/mm/yyyy, pre filled out with todays date, that cannot be edited.

The text area works, but the date is a mess, and no matter how I try etc etc, it stays a mess

Final question my dreamweaver now asks me do I want to open or save a test page called get page.php (in the form action) rather than just opening it, whats changed.

Understand the basic then move on I hope!!

<form
method="post" action="get page.php">
<textarea name="blogtext" rows="15" cols="50">
<?php
echo $_POST['blogtext']
?>
</textarea>
<input type="submit"/>
<input type="text" value="<?php echo date('dd/mm/yyyyy');?>"/>
</form>

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: Basic PHP form stuff

Postby raphael75 » Tue Apr 01, 2014 5:48 am

Georgezx9 wrote:Hi all newbie starting off here and HELP!

I have a form that I want someone to type text into, this will later be saved to an SQL DB.

I also have a date field, that I want to come up as dd/mm/yyyy, pre filled out with todays date, that cannot be edited.

The text area works, but the date is a mess, and no matter how I try etc etc, it stays a mess

Final question my dreamweaver now asks me do I want to open or save a test page called get page.php (in the form action) rather than just opening it, whats changed.

Understand the basic then move on I hope!!

<form
method="post" action="get page.php">
<textarea name="blogtext" rows="15" cols="50">
<?php
echo $_POST['blogtext']
?>
</textarea>
<input type="submit"/>
<input type="text" value="<?php echo date('dd/mm/yyyyy');?>"/>
</form>


You could do something like this:

Code: Select all

<form
               method="post" action="get page.php">
               <textarea name="blogtext" rows="15" cols="50">
               <?php
                      echo $_POST['blogtext']
                ?>
       </textarea>
                <input type="submit"/>
<?php
$d = new DateTime('now');
?>
                  <input type="text" value="<?php echo $d->format('d/m/Y');?>"/>
</form>



But really, if you don't want the date to be editable, you shouldn't bother making it a form field and just display it to the user in a <div>. Then just insert the date without having to worry if the user somehow changed the form field (very simple to do with Firebug).

Georgezx9
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Mar 31, 2014 1:15 pm

Re: Basic PHP form stuff

Postby Georgezx9 » Tue Apr 01, 2014 12:44 pm

Thanks but I still get <?php echo $d->format('d/m/Y');?> in the date field box, not the date.

Thanks

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Basic PHP form stuff

Postby seandisanti » Wed Apr 02, 2014 1:11 am

a few things....
<form
method="post" action="get page.php">
may work, but doesn't look good, use underscores instead of spaces, and it's a good idea to not use the word 'get' in forms you intend to post to, just to avoid confusing the code.

are you sure that you're visiting the page properly? you can't just open the file in a browser, you have to serve it from a webserver, like apache, or iis. using wamp, xamp, or lamp will give you access to the entire application stack you need to serve php pages and databases locally.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 1 guest