Mibble Posted January 19, 2010 Share Posted January 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/ Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 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 = '[email protected]'; $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: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\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. Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-997864 Share on other sites More sharing options...
Mibble Posted January 19, 2010 Author Share Posted January 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-997873 Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 Moved? You will require JS/AJAX to perform this, again using strip_slashes to be a viable validation to automatically create a 'text' component. If i'm understanding what you mean by moving into the other box. Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-997894 Share on other sites More sharing options...
jl5501 Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-997897 Share on other sites More sharing options...
Mibble Posted January 19, 2010 Author Share Posted January 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998283 Share on other sites More sharing options...
jl5501 Posted January 19, 2010 Share Posted January 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998295 Share on other sites More sharing options...
Mibble Posted January 19, 2010 Author Share Posted January 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998300 Share on other sites More sharing options...
jl5501 Posted January 19, 2010 Share Posted January 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998303 Share on other sites More sharing options...
Mibble Posted January 19, 2010 Author Share Posted January 19, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998310 Share on other sites More sharing options...
jl5501 Posted January 19, 2010 Share Posted January 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998318 Share on other sites More sharing options...
Mibble Posted January 19, 2010 Author Share Posted January 19, 2010 i will have to do some reading up on it, if i fill in one of the text boxes on the msgentry (main page with boxes) and then go to process1.php and do the echo $_POST['htmmsg1'] i do not get anything at all. i do appreciate your help! Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998323 Share on other sites More sharing options...
jl5501 Posted January 19, 2010 Share Posted January 19, 2010 when you see the page process.php show up after the submit, you can get to see the entire $_POST array by doing print_r($_POST); THat will show you everything that is there Quote Link to comment https://forums.phpfreaks.com/topic/188986-formaction/#findComment-998330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.