Need *particular* PHP Script

They have: 9 posts

Joined: May 2002

Hi, all!

I have some PHP scripts for some forms but I can't seem to get it to do what I need.

For each form field that is not entered, I need the form to indicate which fields were left blank in the following format:

"Please enter your name" --- appears in red if not entered

"Please enter your e-mail address"

Etc.

The scripts I have will indicate which fields were left unfilled but it's all generated at the top of the page rather than next to each unfilled field.

Any assistance would be appreciated.

Cheers,

Fredman

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Have you searched http://hotscripts.com or http://resourceindex.com for what you want?

If you can't find one, it probably wouldn't be too difficult to modify the script you have.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 9 posts

Joined: May 2002

Hi, Mark!

Yeah, I've looked there but can't quite find what I need.

Any hints on how to modify?

Cheers,

Fred

They have: 9 posts

Joined: May 2002

BTw, a copy of the script I'm trying to edit can be found here: http://www.omt.net/imediatouch/1.php

It places the red text following no input at the top (I want it on top of each unentered field instead) and it doesn't keep what the user already entered, forcing the user to input everything as well as what was missed again.

Oh yes, I also need it to redirect to a specific page after processing rather than refresh the same page and be able to include check box fields entered.

Sorry if I sound like I'm asking for a lot, I'm pretty much a newbie at this stuff.

Thanks Wink

Fred

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I need to see the source.

Busy's picture

He has: 6,151 posts

Joined: May 2001

for the form fields you can do it with if statements, this is a very rough example.

<?php
<form ....>
<
font color=\" if(!fname){ echo(\"red\"); }
    else { echo (\"black\"); }\">Please enter your name</font><br>
<input type=\"text\" name=\"fname\"><br>
<font color=\" if(!fmail){ echo(\"red\"); }
    else { echo (\"black\"); }\">Please enter your email</font><br>
<input type=\"text\" name=\"fmail\"><br>
....
</form>
?>

check box fields are similar, used the the 'name' value, each form field should have a name=something.

the method in the form tag is your redirect bit, you can also surround the form in a if(!submit) ... to make sure all values have options.

I didnt see the page, but as Mark said, display the code and exact help can be given.

They have: 9 posts

Joined: May 2002

Thanks, guys for the help. Here's the code, as per your requests. Thanks for your continued help!

///

Order your iMediaTouch Demo CD!

 

<?php
if($first_name && !$email){ echo ' <font face="Verdana" size=2 color=red><center> E-mail address is a required field </center></font>';
//destroy that name so we see the form again.
$first_name ="";
}
if(!
$first_name){
if(
$email && !$first_name){ echo ' <font face="Verdana" size=2 color=red><center> Your name is required to send this message </center></font>'; } 
echo
'

<FORM method="POST" action="./1.php">

<div align="center">
  <table border="0" width="442" height="365" cellspacing="0" cellpadding="0">
    <tr>
      <td width="479" height="22" bgcolor="#D9F2FF" valign="middle">
        <p align="left">&nbsp; Fields marked with <font color="#FF0000">*</font> are required</td>
    </tr>
    <center>
    <tr>
      <td width="479" height="22" bgcolor="#F2F2F2" valign="middle">
        <table width="419">
          <tr>
            <td vAlign="center" align="left" width="205">
              <p class="bodytext"><font color="#ff0000">*</font><b>First Name</b></p>
            </td>
            <td vAlign="top" align="left" width="205"><input maxLength="30" size="30" name="first_name">&nbsp;</td>
          </table>
          <table width="422">
            <tr>
              <td vAlign="center" align="left" width="203">
                <p class="bodytext"><font color="#ff0000">*</font><b>Last Name</b></p>
              </td>
              <td vAlign="top" align="left" width="205"><input maxLength="80" size="30" name="last_name">&nbsp;</td>
            </table>
            <table width="423">
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>Job Title</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><input maxLength="50" size="30" name="title">&nbsp;</td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>Company/Station
                  ID</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><input maxLength="80" size="30" name="company">&nbsp;</td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>State/Prov</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><input maxLength="80" size="18" name="state">&nbsp;</td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>Country</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><select name="country">
                    <option selected>United States
                    <option>Canada
                    <option>Argentina
                    <option>Africa
                    <option>Australia
                    <option>Austria
                    <option>Belgium
                    <option>Brazil
                    <option>Caribbean
                    <option>Chile
                    <option>China
                    <option>Colombia
                    <option>Croatia
                    <option>Czech Republic
                    <option>Denmark
                    <option>Europe
                    <option>Finland
                    <option>France
                    <option>Germany
                    <option>Greece
                    <option>Hong Kong
                    <option>Hungary
                    <option>India
                    <option>Ireland
                    <option>Israel
                    <option>Italy
                    <option>Japan
                    <option>Korea
                    <option>Latin America
                    <option>Luxemburg
                    <option>Malaysia
                    <option>Mexico
                    <option>Middle East
                    <option>Netherlands
                    <option>New Zealand
                    <option>North Africa
                    <option>Norway
                    <option>Peru
                    <option>Poland
                    <option>Portugal
                    <option>Russia
                    <option>Singapore
                    <option>Slovakia
                    <option>Slovenija
                    <option>South Africa
                    <option>Spain
                    <option>Sweden
                    <option>Switzerland
                    <option>Taiwan
                    <option>Thailand
                    <option>Turkey
                    <option>United Kingdom
                    <option>Uruguay
                    <option>Venezuela</option>
                  </select>&nbsp;</td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>Phone</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><input maxLength="40" size="30" name="phone">&nbsp;</td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202">
                  <p class="bodytext"><font color="#ff0000">*</font><b>E-mail
                  Address</b></p>
                </td>
                <td vAlign="top" align="left" width="207"><input size="30" name="email"></td>
              </tr>
              <tr>
                <td vAlign="center" align="left" width="202"></td>
                <td vAlign="top" align="left" width="207">Add me to the OMT
                  Newsletter list:<br>
                  <input type="checkbox" value="ON" name="add_to_newsletter">Yes&nbsp;
                  <input type="checkbox" value="ON" name="do_not_add_to_newsletter">No</td>
              </tr>
            </table>
          </td>
    </tr>
    <tr>
      <td width="479" height="22" bgcolor="#D9F2FF" valign="middle">
        <table width="441" height="131">
          <tr>
            <td vAlign="top" align="left" width="433" colSpan="2" height="20">
              <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"></b><font color="#ff0000"><br>
              *</font><b>Which of the following products are you interested in?</b></p>
            </td>
          </tr>
          <tr>
            <td vAlign="top" align="left" width="167" height="20">
              <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><br>
              Broadcast Automation</b></p>
            </td>
            <td vAlign="top" align="left" width="260" height="20">&nbsp;</td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="167" height="17">
              <p class="bodytext"><input type="checkbox" value="ON" name="IMEDIATOUCH">iMediaTouch</p>
            </td>
            <td vAlign="middle" align="left" width="260" height="17">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="167" height="17">
              <p class="bodytext"><input type="checkbox" value="ON" name="LOGGER">iMediaLogger</p>
            </td>
            <td vAlign="middle" align="left" width="260" height="17">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="167" height="16">
              <p class="bodytext"><input type="checkbox" value="ON" name="ADCAST">iMediaAdCast</p>
            </td>
            <td vAlign="middle" align="left" width="260" height="16">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="167" height="9">
              <p class="bodytext"><input type="checkbox" value="ON" name="EXPRESSENCODER">iMediaExpressEncoder</p>
            </td>
            <td vAlign="middle" align="left" width="260" height="9">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="167" height="8"><input type="checkbox" value="ON" name="EXPRESSENCODER">iMediaMultiStream</td>
            <td vAlign="middle" align="left" width="260" height="8">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="33" bgcolor="#D9F2FF" valign="middle">
        <table width="471">
          <tr>
            <td vAlign="middle" align="left" width="272" colspan="2"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><br>
              Educational Broadcast Training</b></td>
            <td vAlign="top" align="left" width="185"></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="174"><input type="checkbox" value="ON" name="QUICPIX">QuicPix</td>
            <td vAlign="middle" align="left" width="100">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
            <td vAlign="top" align="left" width="185"></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="272" colspan="2"><b><img border="0" src="images/horiz1.gif" width="152" height="5"></b><br>
              <b>Media Streaming/Web Hosting</b></td>
            <td vAlign="top" align="left" width="185"></td>
          </tr>
          <tr>
            <td vAlign="middle" align="left" width="174"><input type="checkbox" value="ON" name="BCASTPORT">Broadcastport</td>
            <td vAlign="middle" align="left" width="129">&nbsp;<img border="0" src="images/arrow_right.gif" width="9" height="9">
              <a href="http://"><font color="#004A6F">More info</font></a></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="32" bgcolor="#F2F2F2" valign="middle">
        <table width="471">
          <tr>
            <td width="463" colSpan="2">
              <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><font color="#ff0000"><br>
              *</font>The business for which I am seeking a broadcast software
              solution is best&nbsp;described as</b></p>
            </td>
          </tr>
          <tr>
            <td vAlign="top" align="left" width="165"><select name="business" size="1">
                <option value selected>Please Select</option>
                <option value="single_station">Radio Station
                <option value="net_host">Internet Radio Host
                <option value="tv_station">Television Station
                <option value="education">Broadcast Education
                <option value="other">Other</option>
              </select></td>
            <td vAlign="top" align="left" width="292">If other, please specify: <input size="18" name="other_business"></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="65" bgcolor="#D9F2FF" valign="middle"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><font color="#ff0000"><br>
        *</font>Select the Services you are interested in:</b><br>
        <input type="checkbox" value="ON" name="software_only">Software only<br>
        <input type="checkbox" value="ON" name="support">Support<br>
        <input type="checkbox" value="ON" name="training">Training<br>
        <input type="checkbox" value="ON" name="proservices">Professional
        Services (turnkey installation)<br>
        <input type="checkbox" value="ON" name="undecided">Undecided / None</td>
    </tr>
    <tr>
      <td width="479" height="39" bgcolor="#F2F2F2" valign="middle">
        <table width="470">
          <tr>
            <td width="349">
              <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><font color="#ff0000"><br>
              *</font>Do you currently use a broadcast software solution?</b></p>
            </td>
          </tr>
          <tr>
            <td vAlign="top" align="left" colSpan="6" width="462"><select name="have_solution">
                <option value="a" selected>Please Select</option>
                <option value="NO">No</option>
                <option value="YES">Yes</option>
                <option value="NOT_SPECIFIED">Not specified</option>
              </select>&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="65" bgcolor="#D9F2FF" valign="middle">
        <table>
          <tr>
            <td>
              <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><font color="#ff0000"><br>
              *</font>What is your timeframe for purchasing a broadcast software
              solution?</b></p>
            </td>
          </tr>
          <tr>
            <td vAlign="top" align="left" colSpan="6"><select name="timeframe">
                <option value="SELECT" selected>Please Select</option>
                <option value="30DAYS">Less than 30 days</option>
                <option value="1-3MONTHS">1-3 Months</option>
                <option value="4-6MONTHS">4-6 months</option>
                <option value="6-12MONTHS">6-12 months</option>
                <option value="MORETHAN1YEAR">More than a year</option>
              </select>&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="17" bgcolor="#F2F2F2" valign="middle">
        <table>
          <tbody>
            <tr>
              <td colSpan="2" height="15">
                <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><font color="#ff0000"><br>
                *</font>How did you find us?</b></p>
              </td>
            </tr>
            <tr>
              <td vAlign="top" align="left" height="5"><select name="how_found" size="1">
                  <option value selected>Please Select</option>
                  <option value="AD">Advertisement</option>
                  <option value="SEARCH_ENGINE">Internet Search Engine</option>
                  <option value="TRADESHOW">Tradeshow</option>
                  <option value="WOM">Word-of-Mouth</option>
                  <option value="REFERRAL">Customer Referral</option>
                  <option value="DIRECTMAIL">Direct Mail</option>
                  <option value="OTHER">Other</option>
                </select></td>
              <td vAlign="top" align="left" height="5">&nbsp;Other: <input size="18" name="OTHER_FOUND"></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="16" bgcolor="#D9F2FF" valign="middle">
        <table>
          <tr>
            <td vAlign="top" align="left" width="553">
              <table>
                <tbody>
                  <tr>
                    <td>
                      <p class="bodytext"><b><img border="0" src="images/horiz1.gif" width="152" height="5"><br>
                      Comments &amp; Questions:</b></p>
                    </td>
                  </tr>
                  <tr>
                    <td vAlign="top" align="left" colSpan="6"><textarea name="comments" rows="5" cols="49"></textarea></td>
                  </tr>
                </tbody>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td width="479" height="16" bgcolor="#F2F2F2">
        <p align="center"><input type="submit" value="Submit!" name="SUBMIT">
        &nbsp;&nbsp;&nbsp; <input type="reset" value="Clear All" name="RESET"></td>
    </tr>
    </table>
'
; } else {
echo
' <center><font face="Verdana" size=2 color=black> Thank You.<BR><font color="black"><a href="http://www.omt.net/imediatouch/downloads/iSeriesWebDemo.exe">Click here</a> to download iMediaTouch!<BR>(35MB Download)</center></font><BR><BR><BR><BR><BR><BR><BR></td></tr><br>'; }
//SET body text
$body="--Form Version 2 Data--\n\n\n";
$body.="First Name: $first_name \n";
$body.="Last Name: $last_name \n";
$body.="Company: $company \n";
$body.="Title: $title \n";
$body.="Company: $company \n";
$body.="State $state \n";
$body.="Country: $country \n";
$body.="Phone: $phone \n";
$body.="E-mail: $email \n";
$body.="Business: $business \n";
$body.="Have Solution: $have_solution \n";
$body.="Timeframe: $timeframe \n";
$body.="How Found: $how_found \n";
$body.="Comments: $comments \n";
if(
$first_name && $email){
//mail("[email protected]","Form Version 2","From: $email \nX-Mailer: PHP/" . phpversion() . "\n". $body);
mail("[email protected]","Form Version 2","From: $email \nX-Mailer: PHP/" . phpversion() . "\n". $body);
}
?>

 

///

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

For future reference, you may be able to save the file as file.phps and upload it to your server, then people can view the source of the php file. I find it's a useful trick for showing source. The only caveat is that the source replaces every space with a non-breaking space, which means if you copy and paste, the code won't work. Hard to find that error if you don't know about the space/non-breaking space issue.

I'm not going to be much help with the php part (sorry) but you might find it easier to edit this file if you ditch the font tags. And possibly fix the code up, but that's a whole other area.

It looks like the code only checks for a name and email. It doesn't check any of the other form fields at all. Did you want it to check all the form fields?

You might find JavaScript data validation an option.

They have: 9 posts

Joined: May 2002

Thanks for the tips. Wink
Well, the trick is that I don'tknow much about PHP tagging and am in a serious hurry to figure this out. I'm using Javascript validation on the original version of the form along with a CGI formmail script, but my boss needs the PHP version. That's why it only checks for name and e-mail right now, because my attempts at playing with the code aren't working.

Here's the code online:
http://www.omt.net/imediatouch/1.phps

Cheers,
Fred

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

If you know how to use the JavaScript validation (testing), you can do the same thing with PHP. I'm sure there is a more efficient way to do this, but since you're in a hurry, I'll see if maybe this will help.

First, when I try to do programming beyond my skill, I work out how I want it to work -- if this field is empty, show this alert, else move on to next field. What I would ideally like to see is that the entire form is returned with all typed values in place (except bad ones, like non-valid email addresses, et cetera), but that might be too much? (if no, show alert, else print typed value). It would mean splitting the form into two pages, one that does the form and gets the values right, and the next that takes the details from the form and prints them with a confirmation note.

Then, another trick (I'm all about tricks):

Email: ">

Or alternatively...

<? if (test) { ?>

Email:

<? } elseif (other test) { ?>

Email address needs to be in [email protected] format
Email:

<? } else { ?>

Email: ">

<? } ?>

...

That sort of thing.

Does that help at all?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.