Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Basic PHP form stuff

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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>
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 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).
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 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
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 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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.