Page 1 of 2

Having trouble with this form...

Posted: Fri Aug 18, 2006 3:34 pm
by train
Okay, this Drupal module I am using has this registration form that is generated based upon data fields that you create. Most of them are going to be visible to the user. However, some I need to have hidden and some I need to fill in myself.

I cannot get this to work. I am sure it is something basic. I am new to PHP but I know that if I dont return this data the right way, the form will not work.

I cannot enclose this in php tags, or I get
Parse error: parse error, unexpected '<' in C:\DEV\xampp\htdocs\drupal\joshadd\reg.php on line 5
And I am not sure why.

Here is the code (a piece of it...) that I am talking about. You will see at the end of this form. I need to populate:

Code: Select all

&nbsp;<input id="custom_1[M]" name="custom_1[M]" type="hidden" value=$month>
</select>
&nbsp;<input id="custom_1[d]" name="custom_1[d]" type="hidden" value=$day>
</select>
&nbsp;<input id="custom_1[Y]" name="custom_1[Y]" type="hidden" value=$year>
with the current month, day and year. This is the main thing I am trying to do that I cannot do. I need the fields to be hidden and for them to be set to the current day and month and year.

What am I doing wrong? I really appreciate your input.

The form:

Code: Select all

<?PHP

<form  action="http://192.168.1.30/drupal/index.php?q=civicrm/profile/edit&gid=1&reset=1" method="post" name="Edit" id="Edit">


  <div><input name="_qf_default" type="hidden" value="Edit:cancel" />
<input name="postURL" type="hidden" value="http://www.ulem.org/profile_sent!" />
<input name="cancelURL" type="hidden" value="http://www.ulem.org/profile_cancelled!" />
<input name="errorURL" type="hidden" value="http://www.ulem.org/error_page!" />
</div>


<script type="text/javascript" src="./modules/civicrm/js/Common.js"></script>
<div id="crm-container" lang="en" xml:lang="en">
<td><select class="form-date required" id="birth_date[M]" name="birth_date[M]">
	<option value="">-month-</option>
	<option value="1">Jan</option>
	<option value="2">Feb</option>
	<option value="12">Dec</option>
</select>&nbsp;<select class="form-date required" id="birth_date[d]" name="birth_date[d]">
	<option value="">-day-</option>
	<option value="1">01</option>
	<option value="31">31</option>
</select>&nbsp;<select class="form-date required" id="birth_date[Y]" name="birth_date[Y]">
	<option value="">-year-</option>
	<option value="1906">1906</option>
	<option value="1907">1907</option>
</select>
	<option value="">- select -</option>
	<option value="1000">Alabama</option>
	<option value="1001">Alaska</option>
	<option value="1052">American Samoa</option>
	<option value="1002">Arizona</option>
</select></td></tr>
<input name="custom_10" type="text" value="" id="custom_10" class="form-text" /></td></tr><tr><td class="label"><label for="custom_11">Best Time to Contact?</label></td>

<td><select size="5" multiple="multiple" name="custom_11[]" id="custom_11" class="form-select">
	<option value="1">Morning</option>
	<option value="2">Afternoon</option>
	<option value="3">Evening</option>
	<option value="4">Any Time</option>
</select></td></tr><tr>
<td class="label"><label for="custom_7">Race</label></td><td><select size="5" multiple="multiple" name="custom_7[]" id="custom_7" class="form-select">
	<option value="1">Black / African American</option>
	<option value="2">Latino / Latina</option>
	<option value="3">White / Caucasian</option>
	<option value="4">Asian</option>
	<option value="5">Other</option>
</select></td></tr><tr>
<td class="label"><label for="custom_8">Other Race</label></td><td><input name="custom_8" type="text" value="" id="custom_8" class="form-text" /></td></tr><tr><td class="label">
<label>Gender</label></td><td><input value="1" type="radio" id="qf_2bd588" name="gender" /><label for="qf_2bd588">Female</label>&nbsp;<input value="2" type="radio" id="qf_166521" name="gender" /><label for="qf_166521">Male</label>


$day =  date(d);
$month = date(m);

</td><td>&nbsp;<input id="custom_1[M]" name="custom_1[M]" type="hidden" value=$month>
</select>&nbsp;<input id="custom_1[d]" name="custom_1[d]" type="hidden" value=$day>
</select>&nbsp;<input id="custom_1[Y]" name="custom_1[Y]" type="hidden" value="2006">


</select></td></tr></table><div class="messages help"><center>Once you submit this form, this window will close.</center></div></fieldset></div><div class="crm-submit-buttons"><input class="form-submit default" name="_qf_Edit_next" value="Save" type="submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="form-submit default" name="_qf_Edit_cancel" value="Cancel" type="submit" /></div>

  </script>

</form>

?>
This doesnt even come close to working. I get the aforementioned error message about the unexpected bracket. It is making me crazy. Im really sorry I am such a noob... but I am and have to start somewhere... The above form has been edited for relative brevity...

Train

Posted: Fri Aug 18, 2006 3:37 pm
by RobertGonzalez
You cannot mix PHP and HTML without going into and out of PHP...

Code: Select all

<?php
$this_var = 'Hello';
$other_var = 'World';
?>

<div>
    <span class="left"><?php echo $this_var;?></span>
    <span class="right"><?php echo $other_var; ?></span>
</div>

Posted: Fri Aug 18, 2006 3:39 pm
by train
Everah wrote:You cannot mix PHP and HTML without going into and out of PHP...

Code: Select all

<?php
$this_var = 'Hello';
$other_var = 'World';
?>

<div>
    <span class="left"><?php echo $this_var;?></span>
    <span class="right"><?php echo $other_var; ?></span>
</div>
But then can I access those php variables in the input html tags?

Posted: Fri Aug 18, 2006 3:43 pm
by RobertGonzalez
train wrote:But then can I access those php variables in the input html tags?
That is what that piece of code is doing. It is taking them from PHP and displaying them in HTML.

Posted: Fri Aug 18, 2006 3:48 pm
by train
Everah wrote:
train wrote:But then can I access those php variables in the input html tags?
That is what that piece of code is doing. It is taking them from PHP and displaying them in HTML.
Dude, thank you SO MUCH. Honest to God... I feel like a dummy asking these questions but I fought with that all day. I really really appreciate you taking the minute to help me out. Thanks man.

Tt

Posted: Fri Aug 18, 2006 3:50 pm
by s.dot
Everah wrote:You cannot mix PHP and HTML without going into and out of PHP...
Can too :-P

Code: Select all

<?php
$this = 'Hello';
$that = 'World';

echo '<input type="hidden" name="this" value="'.$this.'">
<input type="hidden" name="that" value="'.$that.'">';
?>

Posted: Fri Aug 18, 2006 3:57 pm
by RobertGonzalez
Sorry, I should have clarified that statement. The way he was doing it before was not proper and he cannot mix PHP and HTML that way. Echoing data is a totally valid way of doing things.

Sory for misguiding you.

Posted: Fri Aug 18, 2006 5:36 pm
by train
Everah wrote:Sorry, I should have clarified that statement. The way he was doing it before was not proper and he cannot mix PHP and HTML that way. Echoing data is a totally valid way of doing things.

Sory for misguiding you.
Okay... what if I wanted to get an input HTML value into a PHP variable?

Like at the end of the form, if I wanted that submit button to send an email in addition to submitting the form. How would I get the value of a given checkbox into a $var and add php code to the button?

Is that possible?

Thanks!

Posted: Fri Aug 18, 2006 5:57 pm
by RobertGonzalez

Code: Select all

<?php
$custom_1_m = ( isset($_POST['custom_1['M']]) ) ? $_POST['custom_1['M']] : '';

// Or, an alternative way...
$custom_1_m = '';
if ( isset($_POST['custom_1['M']] )
{
    $custom_1_m = $_POST['custom_1['M']];
}
?>
Or something along those lines. You want to use the superglobal array $_POST for data sent by a form.

Posted: Fri Aug 18, 2006 6:07 pm
by train
Everah wrote:
Or something along those lines. You want to use the superglobal array $_POST for data sent by a form.
I didnt know that. Thanks a lot. This has been really helpful.

Posted: Fri Aug 18, 2006 6:11 pm
by train
Everah wrote:

Code: Select all

<?php
$custom_1_m = ( isset($_POST['custom_1['M']]) ) ? $_POST['custom_1['M']] : '';

// Or, an alternative way...
$custom_1_m = '';
if ( isset($_POST['custom_1['M']] )
{
    $custom_1_m = $_POST['custom_1['M']];
}
?>
Or something along those lines. You want to use the superglobal array $_POST for data sent by a form.
How about the submit button? That is the part I dont think I can add any PHP code to... can I?

Thanks a lot, this really helps.

Posted: Fri Aug 18, 2006 6:15 pm
by RobertGonzalez
Code to the submit botton? Please clarify. For the record, you are not adding code to any part of the HTML. You are outputting HTML to the form. Which you can do the same thing for a button.

Posted: Fri Aug 18, 2006 8:18 pm
by train
Everah wrote:Code to the submit botton? Please clarify. For the record, you are not adding code to any part of the HTML. You are outputting HTML to the form. Which you can do the same thing for a button.
This form is submitted when the button is pressed. But I also want to send an email out here based on variables in the form. I can only be sure the fields are filled out when the submit button is pushed... and when it is, I want to do some emails.

Thanks...

Posted: Fri Aug 18, 2006 9:17 pm
by Ambush Commander
So essentially you've tied two actions to the form? Still not understanding you. If you want to send emails based on the validity of the form, you can always do the validation and then chicken out if it doesn't work (and not send the email).

Posted: Fri Aug 18, 2006 9:21 pm
by jmilane
Ambush Commander wrote:So essentially you've tied two actions to the form? Still not understanding you. If you want to send emails based on the validity of the form, you can always do the validation and then chicken out if it doesn't work (and not send the email).
This is just like me.