import_request_variables , Alternative means of use

I’m looking for alternative ways of use for import_request_variables, I seen extract is something I can do but I cannot get it to work properly… That is assuming I’m doing it right…

Below is my code:

[php]

#volunteer form * { font-family: sans-serif; font-size: 20px !important; } #volunteer form h1, h1 * { font-size: 30px !important; } #volunteer form h2 { font-size: 25px; } #volunteer form table.fillin input { border: none; border-bottom: 1px solid black; float: left; padding: 1px 3px; } #volunteer form input.fullsize { width: 40em; } #volunteer form input.halfsize { width: 15em; } #volunteer form input.quartersize { width: 7.5em; } #volunteer form input#state_field { width: 4em; } #volunteer form table.fillin th { text-align: right; } #volunteer form table.fillin td { text-align: left; } #volunteer form hr { border: none; border-bottom: 2px dashed black; } #volunteer form table.check { vertical-align: top; } #volunteer form address { font-style: normal; margin-left: 10em; }
<?php

$target_email = "[email protected]";
$target_subject = “VOLUNTEER SUBMISSION”;
$from_address = “[email protected]”;

/* No user-servicable parts inside. */

/* http://php.net/import_request_variables */
import_request_variables(“p”, “posted_”);

$mail_format = <<<MAILFORMAT
Name: $posted_name_field
Address: $posted_address_field
City: $posted_city_field
State: $posted_state_field
County: $posted_county_field
ZIP: $posted_zip_field
Home Phone: $posted_homephone_field
Mobile Phone: $posted_mobilephone_field
E-mail: $posted_email_field


He/she is willing to:
[$posted_election_field] Circulate Petitions
[$posted_volunteer_field] Volunteer at events
[$posted_recruit_field] Help recruit other volunteers
[$posted_yardsigns_field] Put up Yard Signs
[$posted_endorse_field] Use my Name to Endorse
[$posted_phone_field] Make Phone Calls
[$posted_fundraise_field] Fundraise / Host Events
[$posted_letters_field] Write letters to the Editor
[$posted_helpinoffice_field] Help in Office / Data Entry


Comments/Interests:
$posted_comments_field


Form submitted %s from IP %s.

MAILFORMAT;

$mail_text = sprintf($mail_format, date(DATE_RFC822), $_SERVER[‘REMOTE_ADDR’]);

if ($posted_name_field) {
/* send_mail() returns false if there is a failure */
if (mail($target_email, $target_subject, $mail_text, “From: $from_address”)) {
print “

Sent! Thank you for your response!

Content of message:

$mail_text
”;
exit();
} else {
print “

Failure when sending message!

Please notify <a href=“mailto:$target_email”>$target_email of this issue

”;
}
} else {
$show_form = 1;
}

/* Show the form if we have to. */
if ($show_form == 1) {
?>

YES! I want to volunteer to help the
Committee

<div align="center">
      <p>All Information is required. (except Mobile)</p>
        <table width="663" class="fillin">
          <tr><td width="639" height="89"><div align="center">
            <table border='0'><tr><td>Name :</td><td>
                <input class="halfsize" id="name_field" name="name_field" type="text" />
              </td><td>Address:</td><td>
              <input class="halfsize" id="address_field" name="address_field" type="text" /> 
              </td><td>City :</td><td>
              <input class="halfsize" id="city_field" name="city_field" type="text" />
              </td></tr><tr><td>County:</td><td>
              <input class="halfsize" id="city_field2" name="county_field" type="text" />
              </td><td> State :</td><td>
              <input name="state_field" type="text" id="state_field" /> 
              </td><td> ZIP :</td><td>
              <input name="zip_field" type="text" class="quartersize " id="zip_field" />
              </td></tr><tr><td>
              Home:</td><td>
              <input class="halfsize" id="homephone_field" name="homephone_field" type="text" />
	  </td><td>Mobile :</td><td>
              <input name="mobilephone_field" type="text" class="check " id="mobilephone_field" />
              </td><td>E-mail:</td><td>
              <input class="halfsize" id="email_field" name="email_field" type="text" />
              </td></tr></table>
          <p>&nbsp;</p>
              </div>
                </td>
          </tr>
      </table>
    <br />
  </div>
        
<h2 align="center">I am willing to (check all that apply):</h2>
      <div align="center">
        <table class="check">
          <tr><td width="272">
            <input id="election_field" name="election_field" type="checkbox" />
            <label for="election_field">Circulate Petitions</label>
            <br />
            <input id="volunteer_field" name="volunteer_field" type="checkbox" />
            <label for="volunteer_field">Volunteer at events</label>
            <br />
            <input id="recruit_field" name="recruit_field" type="checkbox" /> <label for="recruit_field">Help recruit other volunteers</label>
            <br />
            <input id="yardsigns_field" name="yardsigns_field" type="checkbox" /> <label for="yardsigns_field">Put up Yard Signs</label>
            <br>
            <input id="endorse_field" name="endorse_field" type="checkbox" />
            Use my Name to Endorse<br />
            </td><td width="18">&nbsp;&nbsp;&nbsp;</td>
        <td width="381">
          <input id="phone_field" name="phone_field" type="checkbox" /> <label for="phone_field">Make phone calls</label>
          <label for="door2door_field"></label>
          <br />
          <input id="fundraise_field" name="fundraise_field" type="checkbox" />
          <label for="fundraise_field">Fundraise</label>
          / Host Events<br />
          <input id="letters_field" name="letters_field" type="checkbox" />
          Write letters to the editor<br>
          <input id="helpinoffice_field" name="helpinoffice_field" type="checkbox" />
          Help with Office Mailings / Data Entry
          <br />            </td></tr>
        </table>
        <br />
        <br />
        <b>Comments/Interests:</b><br />
        <textarea name="comments_field" cols="70" rows="10" class="check" id="comments_field"></textarea>
        
        <br />
        <br />
        <input type="submit" value="SUBMIT" />
  </div>
<?php } ?>
[/php]

First thing, that function is depracated. Dont use it.

From the Manual: This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Second, it is not a good idea to just extract variables from your POST array. It can get difficult in a larger app to know where the variables came from.

It is better to use {$_POST[‘name_field’]} that way it is obvious where the data is coming from. The point where you would turn that into a NEW variable is if you did some action on it such as sanitizing the data like so:

$name_field = sanitizer_function($_POST[‘name_field’]);

Also, you can remove the _field from the form names. If you use {$_POST[‘name’]} it is obvious it came from a form.

I did a few modifications

[php]He/she is willing to:
{$_POST[‘election_field’]}Circulate Petitions
{$_POST[‘volunteer_field’]}Volunteer at events
{$_POST[‘recruit_field’]}Help recruit other volunteers
{$_POST[‘yardsigns_field’]}Put up Yard Signs
{$_POST[‘endorse_field’]}Use my Name to Endorse
{$_POST[‘phone_field’]}Make Phone Calls
{$_POST[‘fundraise_field’]}Fundraise / Host Events
{$_POST[‘letters_field’]}Write letters to the Editor
{$_POST[‘helpinoffice_field’]}Help in Office / Data Entry[/php]

I’m not following as to what else i need to do , in its current state it posts, but does not email the info

Change
[php]if ($posted_name_field) {[/php]

TO

[php]if ($_POST) {[/php]

The system emailed me, however it didnt grab any information that i manually input to each of the fields.

It did however grab the ON or off associated with ticking of the boxes.

[php]

All Information is required. (except Mobile)




Name :

Address:

City :

County:

State :

ZIP :


Home:


Mobile :

E-mail:

[/php]

I am rewriting it now…

Wait never mind, I got it Thank you!

I forgot I needed to add in

[php]$mail_format = <<<MAILFORMAT
Name: {$_POST[‘name_field’]}
Address: {$_POST[‘address_field’]}
City: {$_POST[‘city_field’]}
State: {$_POST[‘state_field’]}
County: {$_POST[‘county_field’]}
ZIP: {$_POST[‘zip_field’]}
Home Phone: {$_POST[‘homephone_field’]}
Mobile Phone: {$_POST[‘mobilephone_field’]}
Email: {$_POST[‘email_field’]}

Comments: {$_POST[‘comments_field’]}
[/php]

Thank you, I donated to you!

I attempted your change I received this error

Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/partmi/public_html/wp-content/themes/InterPhase/volunteer.php on line 138

[php]



YES! I want to volunteer to help the

Committee

[/php]

Changes I would make is use css to format your page instead of tables and group the services into an array like so:

[php]Circulate Petitions
Volunteer[/php]

Then replace the PHP with the following (take note of the foreach that parses your services array line 26)

[php]<?php
if ($_POST)
{

$target_email   = "[email protected]";
$target_subject = "VOLUNTEER SUBMISSION";
$from_address   = "[email protected]";

$mail_format = <<<MAILFORMAT

Name: {$_POST[‘name’]}
Address: {$_POST[‘address’]}
City: {$_POST[‘city’]}
State: {$_POST[‘state’]}
County: {$_POST[‘county’]}
ZIP: {$_POST[‘zip’]}
Home Phone: {$_POST[‘homephone’]}
Mobile Phone: {$_POST[‘mobilephone’]}
E-mail: {$_POST[‘email’]}


He/she is willing to:

MAILFORMAT;

foreach ($_POST['services'] as $service)
    {
    $mail_format .= "$service\n";
    }

$mail_format .= <<<MAILFORMAT

Comments/Interests:
{$_POST[‘comments’]}


Form submitted from IP {$_SERVER[‘REMOTE_ADDR’]}.
MAILFORMAT;

/* send_mail() returns false if there is a failure */
if (mail($target_email, $target_subject, $mail_format, "From: $from_address"))
    {
    print "<h1>Sent! Thank you for your response!</h1><h2>Content of message:</h2><pre>$mail_format</pre>";
    exit();
    }
else
    {
    print "<h1>Failure when sending message!</h1><h2>Please notify <a href=\"mailto:$target_email\">$target_email</a> of this issue</h2>";
    }
exit;
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service