Thanks in advance for your help. I am new to PHP. I have done a lot of learning to get to this point, but I am currently stuck.
I have a form with a 'fields-section' and a 'proof-section' that has 3 buttons - proof, edit and send. Initially, the 'fields-section' is displayed and the 'proof-section' is hidden. Of the 3 buttons, the 'proof' button is visible while the other 2 are not. After the form is completed and 'proof' is clicked, the fields are validated, some fields are transformed into Hebrew and a proof is presented to the user by hiding the 'fields-section' and showing the 'proof-section'. Here the 'edit' and 'send' buttons are available and the 'proof' button is hidden. I am integrating this form within a Wordpress page template.
I am finding that the PHP variables do not have any value and I don't understand why.
If I change echo htmlspecialchars($line1);
to
if(isset($_POST['line1'])){
echo htmlspecialchars($_POST['line1']);
}
It works...but this solution doesn't work for $line1_hebrew
because this is a calculated field. I deleted unnecessary code below to keep it short.
Below is my code from the Wordpress template:
<?php
include "hebrew-memorial-creator.php";
add_action( 'genesis_after_loop', 'em_form');
/**
* Output the form to the page
*
*/
function em_form() {
?>
<div id="hebrew-memorial-creator">
<form name="hebrewMemorialForm" action="" method="POST">
<div id="field_section">
<div>
<label for="line1">Line 1: </label><input type="text" name="line1" id="line1" value="<? echo htmlspecialchars($line1);?>" size="50" maxlength=40 />
<input type="hidden" name="line1_hebrew" id="line1_hebrew" value="<?php htmlspecialchars($line1_hebrew);?>" />
</div>
.... deleted some fields here
</div><!--field-section-->
<input type="submit" id="proof_button" name= "proof_button" value="PROOF">
<input type="submit" id="edit_button" name="edit_button" value="EDIT">
<input type="submit" id="submit_button" name="submit_button" value="SEND">
<div id="proof_section">
<?php echo htmlspecialchars($proof);?>
</div><!--proof-section-->
</form>
</div><!--hebrew-memorial-creator-->
<?php
} // end function em_form
genesis();
?>
Below is my code from hebrew-memorial-creator.php:
<?php
if (isset($_POST['line1'])) { $line1 = $_POST['line1']; }
... deleted code for other fields...
if(isset($_POST['proof_button'])) {
$formerrors = false;
// validate fields
// email address is required
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'email error';
$emailErr = 'Please enter a valid email address';
$formerrors = true;
}
if (! ($formerrors)) {
// for line1 - line4, create line1_hebrew - line4_hebrew - converting lowercase letters to Hebrew characters
// and write to hidden form fields
$line1_hebrew = convert($line1);
... deleted code for additional fields
// all fields validated
// show proof fields and submit/proof buttons
$proof = '<div class="bronze"><p style="font-size: 36px; text-align:center;">HERE IS YOUR PROOF :</p>';
$proof .= '<p>Line1: ' . htmlspecialchars($line1) . ' ==> ' . htmlspecialchars($line1_hebrew) . '</p>';
... deleted code for other fields
$proof .= '</div>';
$proof .= "<script>
$('#field_section').hide();
$('#proof_section').show();
$('#proof_button').hide();
$('#edit_button').show();
$('#submit_button').show();
$('html,body').scrollTop(0);
</script>";
` // curious if anyone has a better solution to hiding/showing field`
} // end if no errors
return;
} // end proof button pressed
if (isset($_POST['submit_button'])) {
....deleted formatting of mail variables
mail( $to, $subject, $message, $headers );
wp_redirect( get_site_url() . '/thank-you');
} // end send button pressed
// replacing any lowercase characters with their hebrew character equivalent
function convert($line) {
if (($line == '') || ($line == ' ')) {
return $line;
}
$newLine = "";
for ($i=0; $i < strlen($line); $i++) {
//$character = substr($line, $i, 1);
$character = $line[$i];
... deleted code
} // end for
return $newLine;
} // end function convert
?>