View unanswered posts | View active topics It is currently Thu Dec 14, 2017 6:29 am



Reply to topic  [ 2 posts ] 
 Need help finishing form 
Author Message
Junior Member

Joined: Thu Jan 21, 2010 9:53 pm
Posts: 1
Location: Bridgeport, NE
Post Need help finishing form
I am "young" to PHP and I am trying to finish a form that spools to itself until all of the required fields conditions are met. I want this page to go to another page if all of the conditions are met, for two possible instances for one particualr field. If one of the two possible conditions are not met, the page refreshes itself and maintains the previous selections on the refresh until all of the requirements are met. What I am having problems with is if the second radio group is selected "No", the "Required" notification comes up and says that they have to explain why in the text area, but when the Submit button is clicked, the form refreshes itself and has to be clicked again for it to go to the form action url. I apologize for the onclick events, but I am trying something I have yet to try with PHP, and like the "count down" approach next to the radio groups and text area field. Any and all help would be appreciated, and if anyone knows how to do it all in PHP only, that would be great.

Code:
<?php
$missbuy = '';
$misssell = '';
$misswhynotsell = '';

$action = 'form4.php';

if (trim($_POST['buy']) == "") {$action = $_SERVER['PHP_SELF']; $missbuy = '*required';}
if (trim($_POST['sell']) == "") {$action = $_SERVER['PHP_SELF']; $misssell = '*required';}
if (trim($_POST['sell']) == "No" && empty($_POST['whynotsell'])) {$action = $_SERVER['PHP_SELF']; $misswhynotsell = '*required';}
?>
<!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=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php echo $action;?>">
  <table border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td align="right"> </td>
      <td rowspan="8" align="left"> </td>
      <td align="left"> </td>
    </tr>
    <tr>
      <td align="right" valign="middle">Buy?</td>
      <td align="left" valign="middle"><label>
        <input <?php if (!(strcmp($_POST['buy'],"Yes"))) {echo "checked=\"checked\"";} ?> name="buy" type="radio" id="buy_0" value="Yes" onclick="document.forms[0].submit()"/>
        Yes</label>
        <label>
          <input <?php if (!(strcmp($_POST['buy'],"No"))) {echo "checked=\"checked\"";} ?> name="buy" type="radio" id="buy_1" value="No" onclick="document.forms[0].submit()"/>
          No</label>
                <?php echo $missbuy; ?></td>
    </tr>
    <tr>
      <td align="right" valign="middle"> </td>
      <td align="left" valign="middle"> </td>
    </tr>
    <tr>
      <td align="right" valign="middle"> </td>
      <td align="left" valign="middle"> </td>
    </tr>
    <tr>
      <td align="right" valign="middle">Sell?</td>
      <td align="left" valign="middle"><label>
        <input <?php if (!(strcmp($_POST['sell'],"Yes"))) {echo "checked=\"checked\"";} ?> type="radio" name="sell" value="Yes" id="sell_0" onclick="document.forms[0].submit()"/>
        Yes</label>
        <label>
          <input <?php if (!(strcmp($_POST['sell'],"No"))) {echo "checked=\"checked\"";} ?> type="radio" name="sell" value="No" id="sell_1" onclick="document.forms[0].submit()"/>
          No  <?php echo $misssell; ?></label></td>
    </tr>
    <tr>
      <td align="right" valign="middle"> </td>
      <td align="left" valign="middle"> </td>
    </tr>
    <tr>
      <td align="right" valign="top"> </td>
      <td align="left" valign="top"> </td>
    </tr>
    <tr>
      <td align="right" valign="top">

        If you are not selling, please explain why:</td>
      <td align="left" valign="top"><span><?php echo $misswhynotsell; ?>

        </span>
        <textarea name="whynotsell" cols="45" rows="5" id="whynotsell"><?php echo $_POST['whynotsell']; ?></textarea></td>
    </tr>
    <tr>
      <td align="right"> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td align="right"> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="3" align="center" valign="middle"><input name="Submit" type="submit" id="Submit" value="Next >>"/></td>
    </tr>
    <tr>
      <td align="right"> </td>
      <td> </td>
      <td> </td>
    </tr>
  </table>
</form>
</body>
</html>


Thu Jan 21, 2010 10:31 pm
Report this post
Profile
Junior Member

Joined: Tue Jun 08, 2010 8:15 am
Posts: 1
Post Re: Need help finishing form
Ubfortunately, I am beginner in PHP too. So, I know simple example of creating and selecting form. But I am not sure, that it wil help you. So, you can search neccessary information about it here: http://phpforms.net/tutorial/html-basics/php-forms.html - php form.


Tue Jun 08, 2010 8:23 am
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.