Jump to content

Recommended Posts

I have a PHP form and for the date I've got 3 seperate boxes (one for dd, one for mm, and one for yyyy).

 

1. When the form is submitted, how do I make a variable containing all 3 in the format dd/mm/yyyy?

I know it's $date=$_POST[dd] but then how do I add the other 2?

 

2. When the form comes up, instead of having labels, I've set the initial value as the label (ie date for the date box). Is it possible to make this text disappear once the curser goes into that box rather than having to manually delete it?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/134439-help-with-a-php-formtwo-quick-questions/
Share on other sites

1) Concatenation.

 

$final_date = "" . $_POST[dd] . "/" . $_POST[mm] . "/" . $_POST[yyyy] . "";

 

2) Yes.  You can do this using Javascript.

 

onfocus="this.value = ( this.value == this.defaultValue ) ? '' : this.value;return true;">

It's still a working process. I've put the echos in but haven't got it entered into the database yet. Here it is:

<?php
if ($_POST[viewed] != "yes")
{
echo "<form name=\"form1\" method=\"post\" action=\"$SERVER[php_SELF]\">
  <table width=\"200\" border=\"0\">
    <tr>
      <td valign=\"top\"><input name=\"title\" type=\"text\" id=\"title\" tabindex=\"1\" value=\"Event Title\" size=\"80\" maxlength=\"100\"></td>
    </tr>
    <tr>
      <td height=\"27\" valign=\"top\">
  <input name=\"dd\" type=\"text\" id=\"dd\" tabindex=\"2\" value=\"dd\" size=\"5\" maxlength=\"2\">
      <input name=\"mm\" type=\"text\" id=\"mm\" tabindex=\"2\" value=\"mm\" size=\"5\" maxlength=\"2\">
      <input name=\"yyyy\" type=\"text\" id=\"yyyy\" tabindex=\"2\" value=\"yyyy\" size=\"10\" maxlength=\"4\"></td>
    </tr>
    <tr>
      <td valign=\"top\"><input name=\"eventTime\" type=\"text\" id=\"eventTime\" tabindex=\"3\" value=\"Time\" maxlength=\"7\"></td>
    </tr>
    <tr>
      <td valign=\"top\"><input name=\"venue\" type=\"text\" id=\"venue\" tabindex=\"4\" value=\"Venue\" size=\"80\" maxlength=\"100\"></td>
    </tr>
    <tr>
      <td valign=\"top\"><textarea name=\"description\" id=\"description\" cols=\"45\" rows=\"5\" tabindex=\"5\">Enter discription here</textarea></td>
    </tr>
<tr>
  <td valine=\"top\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Add Event\" /></td>
</tr>
<input name=\"viewed\" type=\"hidden\" id=\"viewed\" value=\"yes\">
</table>
</form>";
}
else
{
$title = $_POST[title];
$eventDate = $_POST[dd]."/".$_POST[mm]."/".$_POST[yyyy];
$eventTime = $_POST[eventTime];
$venue = $_POST[venue];
$description = $_POST[description];
echo "<b>".$title."</b><br />".$eventTime." ".$eventDate."<br />".$venue."<br /><br />".$description."<br /><br />This event has been successfully added";
}
?>

 

Thanks again

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.