Skip to content
Advertisement

Splitting user’s full name and passing first name to next form pae

I have an html form which spans over several ‘form pages’. The first form page asks for the user’s full name, which will be passed along through each form page until the form is finally submitted.

However… I would like to ‘extract’ just the user’s first name from the full name field, so I may use it throughout the rest of the form in the sales language (text).

Example:

User’s full name is ‘John Smith’.

‘John Smith’ will be passed along each page, and then submitted with the final form page.

However, I would like to be able to use just ‘John’ in several (text) instances throughout the form, such as;

“OK John, we’ll need a little more information from you to generate your quote.”

I realize I could go a different route and have a first name field and a last name field, but I would rather explore the option of splitting the full name field for these purposes.

I have tried a number of things, but keep hitting a wall. Any advice here would be most appreciated. Thank you.

I have included a scaled down, example version of form page 1 and form page 2.

Form Page 1

<!DOCTYPE html>

<head>

<title>Form Page 01</title>

</head>

<body>

<form action="formPage02.php" method="POST">


<h1>Let's begin your quote!</h1><br><br>

Please provide your full name below:<br><br>


<input type="text" id="userName" name="userName" class="inputField" placeholder=" Enter Your 
Full Name" required><br><br><br>


<input type="submit" class="continueButton" value="Continue">


</form>

</div>   

</body>

</html>

Form Page 2

<!DOCTYPE html>

<head>

<title>Form Page 02</title>

</head>

<body>

<form action="formPage03.php" method="POST">

<!-- The user's full name is carried over in this hidden field. -->
<input type="hidden" name="userName"    value="<?php echo $_POST['userName'];    ?>" />


OK&nbsp; <!-- [first name (only) should print here] -->, we'll need a little more information from you to generate your quote.
from you.<br><br>

Please begin by selecting your age below:<br><br>


<select id="userAge" name="userAge" class="ageField" required>
<option value="0" selected="selected" disabled="disabled">Age</option>
<option value="Under 18">Under 18</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
<option value="41">41</option>
<option value="42">42</option>
<option value="43">43</option>
<option value="44">44</option>
<option value="45">45</option>
<option value="46">46</option>
<option value="47">47</option>
<option value="48">48</option>
<option value="49">49</option>
<option value="50">50</option>
<option value="51">51</option>
<option value="52">52</option>
<option value="53">53</option>
<option value="54">54</option>
<option value="55">55</option>
<option value="56">56</option>
<option value="57">57</option>
<option value="58">58</option>
<option value="59">59</option>
<option value="60+">60+</option>
</select>

<br><br><br>


<input type="submit" class="continueButton" value="Continue">


</form>

</div>   

</body>

</html>

Advertisement

Answer

You can split the userName in PHP using explode and then just echo the first element returned by that:

OK&nbsp;<?= explode(' ', $_POST['userName'])[0] ?>, we'll need a little more information 
from you.<br><br>