Jump to content

form/action


Mibble

Recommended Posts

here is what i am trying to do. Two columns one for html and one for text which will then be used to post (simultaneously) with a single submit button to a mail script. it will be going to some file which pulls the email address' out of the database, so it will be php. however at this time i just need to get it so there is only a single submit button which works sending to the one file which will be programmed in (hardcoded)

any help appreciated

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>columns</title>
</head>

<body>
<table width="100%" border="1">
  <tr>
    <td><form id="form1" name="form1" method="post" action="somefile.php">
        <label>Users HTML<br />
          <textarea name="textarea" cols="35" rows="12"></textarea>
        </label>
    </form>      </td>
    <td><form id="form2" name="form2" method="post" action="somefile.php">
        <label>Users TEXT<br />
          <textarea name="textarea2" cols="35" rows="12"></textarea>
        </label>
      </form>
    </td>
  </tr>
</table>


</body>
</html>

Link to comment
Share on other sites

I'm not sure what you want, but here's an example form with submit button:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>columns</title>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td><form id="form1" name="form1" method="post" action="somefile.php">
        <label>Users HTML<br />
          <textarea name="textarea" cols="35" rows="12"></textarea>
        </label>
    </form>      </td>
    <td><form id="form2" name="form2" method="post" action="somefile.php">
        <label>Users TEXT<br />
          <textarea name="textarea2" cols="35" rows="12"></textarea>
        </label>
      
    </td>
  </tr>
  <tr>
  <td>
  <input type="submit" value="Send mail"/>
  </tr>
  </td>
  </form>
</table>
</body>
</html>

 

Any fields between the <form> elements will be able to be accessed from PHP. Note that it will be (nearly impossible) to send an e-mail the way you want without PHP.

 

In PHP you can access the forms like:

<?php

$message_html = $_POST['textarea'];
$message_nohtml = $_POST['textarea2'];

$to      = 'your@e-mail.com';
$subject = 'Your e-mail';
$message = "E-mail: Only text: \n $message_nohtml \n\n E-mail: With html:\n $message_html \n\n";
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

 

Note you could just use strip_tags on the html field, to remove html so there's no need for two fields if you want it automated, Just giving you the only really viable solution, if you're having troubles don't hesitate to ask on the php forums.

Link to comment
Share on other sites

it is something along this code, once the html area box is filled it moves to the text box area, then the submit button will allow posting. i can work out the validation, etc later wanting to get the form working properly. thus i am doing it via html prior to php.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="100%" border="1">
  <tr>
    <td>box 1
      <form id="form1" name="form1" method="post" action="">
        <label>html text area<br />
          <textarea name="textarea" cols="40" rows="12"></textarea>
        </label>
      </form>
    </td>
    <td>box 2
      <form id="form2" name="form2" method="post" action="">
        <label>enter text here<br />
          <textarea name="textarea2" cols="40" rows="12"></textarea>
        </label>
      </form><input name="submit" type="button" value="submit" />
    </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>

</body>
</html>

Link to comment
Share on other sites

A normal form submit button will only send the fields of the <form> </form> that it is part of.

 

You can have both your fields on one form and even have one hidden until the other is filled in, of you like.

If you want a submit function that is outside the form tags, then you will need some javascript executed on click of that button, to collect the form field values and do something with them, like send them to the server via ajax, as has been suggested.

Link to comment
Share on other sites

ok thanks. is this the right way of dong this? I am cutting out the other parts to the form.

 

program1.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML & TEXT Entry for email</title>
</head>
<body>

<?php
if (!isset($_POST['submitForm'])) {
?> 

<form action="process1.php" method="post">
<strong>All Bidders</strong><br />

  <table>
    <tr>
      <td>HTML Message:<br />
        <textarea name="htmmsg1" cols="50%" rows="10"> </textarea>
      </td>
      <td>TEXT Message:<br />
        (<textarea name="txtmsg1" cols="50%" rows="10"> </textarea>)
      </td>
    </tr>
    <td><input type="submit" name="SubmitForm" value="Submit"></td>
  </table>
</form>
<?php

} else {
echo $htmmsg1;
    echo $txtmsg1;
echo "Form Submitted!";
}
?>
</body>
</html>

 

and process1.php what i want to do for the moment is to display what i have entered into the html and text boxes. In the previous post it was stated the button could be hidden until both boxes are filled. how? I am still learning btw.

 

Thanks

Link to comment
Share on other sites

Ok, now you have both your fields and the submit button in the same form so that is good.

 

you have the action set as process1.php and the method set as post. Also you have the php to handle the processing in the same page, so I assume that this code is all in the file process1.php and you are calling it again to do the processing. If this file is actually program1.php, then you dont need the php to process the form in here at all. you only need that if the same file presents the form, and processes it.

 

In your process code, you are trying to echo form fields directly. This will not work unless you extract() them first.

 

So you can either echo $_POST['htmmsgl']  etc  or ...

extract($_POST);

then you can echo $htmmsgl  etc

Link to comment
Share on other sites

ok perhaps i lost myself. i have made some changes. th3e reason why to process1.php is it will be doing some other processing with the data once completed (emailing select users or all users or categories of users). The html message is the same as the text except text is for those who cannot accept html.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML & TEXT Entry for email</title>
</head>
<body>

<?php
if (!isset($_POST['submitForm'])) {
?> 

<form action="process1.php" method="post">
<strong>All Bidders</strong><br />

  <table>
    <tr>
      <td>HTML Message:<br />
        <textarea name='htmmsg1' cols="50%" rows="10"> </textarea>
      </td>
      <td>TEXT Message:<br />
        <textarea name='txtmsg1' cols="50%" rows="10"> </textarea>
      </td>
    </tr>
<td> </td>
    <td align="right"><input type="submit" name="SubmitForm" value="Submit"><INPUT type="reset">
</td>
  </table>
</form>
<?php

} else {
echo "Form Submitted!";
}
?>
{/code]


and if i understand you correctly:

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML & TEXT Entry for email</title>
</head>
<body>
<?php
extract($_POST);
echo $_POST['htmmsg1']
?>

</body>
</html>

Link to comment
Share on other sites

Ok, if the program1.php is only going to present the form, then you need no php code on that page at all. When the submit button is pressed the processing goes direct to the page specified in the form action, which in your case is process.php

 

In that processing page (process.php) you can access the form field values either by

$_POST['fieldname']   

 

OR

 

extract($_POST);

then they can be accessed as $fieldname

 

so you need to do one OR the other way

 

Link to comment
Share on other sites

this is what is on process1.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML & TEXT Entry for email</title>
</head>
<body>
<?php
extract($_POST);
echo $_POST['htmmsg1']
?>

</body>
</html>
{/code]

Link to comment
Share on other sites

Ok, that is fine, except if you are going to echo $_POST['htmmsgl'] then you do not need to extract.

 

You only need to extract if you want to echo $htmmsgl

 

extract() takes all the array elements and assigns them to variables of the same name.

Link to comment
Share on other sites

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.