How to pass a parameter value from a hyperlink on one page to another page in ExpressionEngine? - expressionengine

I am on an expression engine entry page with a few hyperlinks...
Go Form
Go2 Form
Based on which hyperlink I click, I want to navigate to another expression engine page with a contact form and dynamically set the value of the subject field based on which hyperlink was clicked on the previous page......How do I go about doing this? Can I set a parameter value which then gets passed to the expressionengine session so I can reference it in the Contact Form page? Perhaps a mechanism like the below?
<a href="http://example.com/expressionenginepage/" ee_value=1>Go Form</a>
<a href="http://example.com/expressionenginepage/" ee_value=2>Go2 Form</a>

I've done something similar to this with selects, but the principle is the same for text fields.
Simply treat the 2nd URL segment as the variable.
So you have your form page here:
http://example.com/expressionenginepage/
If you want the subject line on that form to be pre-filled out as "Please call me", compose the link as
http://example.com/expressionenginepage/call
If want the subject line on that form to be pre-filled out as "I need help", compose the link as http://example.com/expressionenginepage/help
Then on your template 'expressionenginepage' look at the segment_2 variable and conditionally serve the subject line that you desire.
{if segment_2 == 'call'}
<input id="subject" type="text" value="Please call me">
{if:elseif segment_2 == 'help'}
<input id="subject" type=text value="I need help">
{if:else}
<input id="subject" type=text value="">
{/if}

Related

Node.js Getting values from html and using req.body.<name>

I am trying to retrieve multiple values from HTML and make use of it using req.body..
I am able to do this via message: req.body.message
<form id="message-form" class="input-group input-group-lg" style="">
<input type="text" name="message" class="form-control" aria-label="Large" aria-describedby="inputGroup-sizing-sm">
<div class="input-group-prepend">
<button class="btn btn-primary">Send</button>
</div>
</form>
However, I would like to retrieve the values from elements that are not inside the e.g <span id="item" style="font-weight:bold"> </span>
The reason is that when I load the page, it renders these values dynamically (retrieved from database). When I want to do a POST, I would like to make use of these values that have been rendered previously.
Is there a way to do this?
Many thanks.
Forms don't submit data that does not appear inside a form control.
So you can either:
Store the data somewhere in the server (such as in a session) where you can read it back on a subsequent request (watch out for race conditions!) or
Put the data in a form control instead of or as well as in the span. (Possibly using a hidden input).

How to create Quiz in modx

I am new to modx and I have to create multipage quiz in my website.
Any suggestion will be helpfull.
While there are more than one way to achieve this, a combination of FormIt
and FormItRetriever extras might just be what you need. FormIt handles the processing of your quiz forms, which includes saving the data in the cache or on the database as a JSON object. And, as the name suggests, FormItRetriever allows you to retrieve previously saved form data on a subsequent page.
Here's a quick example adapted from FormIt's docs:
Page 1
[[!FormIt?
&submitVar=`go`
&hooks=`spam,redirect`
&store=`1`
&redirectTo=`id-of-next-page`
]]
<form action="[[~[[*id]]]]" method="post">
<input type="hidden" name="nospam" value="" />
<label for="qzq1">Quiz question 1: [[!+fi.error.qzq1]]</label>
<input type="text" name="qzq1:required" id="qzq1" value="[[!+fi.qzq1]]" />
<label for="qzq2">Quiz question 2: [[!+fi.error.qzq2]]</label>
<input type="text" name="qzq2:required" id="qzq2" value="[[!+fi.qzq2]]" />
<label for="qzq3">Quiz question 3: [[!+fi.error.qzq3]]</label>
<textarea name="qzq3:stripTags" id="qzq3" cols="55" rows="7">[[!+fi.qzq3]]</textarea>
<br />
<input type="submit" name="go" value="Next" />
</form>
The &store property tells FormIt to store the data in the cache for retrieval using the FormItRetriever snippet.
The &redirectTo property is the ID of your next page. FormIt will use the redirect hook, specified in the &hooks property, to redirect the user when they submit this form.
Page 2:
[[!FormItRetriever]]
[[!FormIt?
&submitVar=`go`
&hooks=`spam,redirect`
&store=`1`
&redirectTo=`id-of-third-page`
]]
/* Page 2 quiz form goes here */
The FormItRetriever snippet will allow you to display your previously saved form data with placeholders relating to the names of your form fields => [!+fi.qzq1]]
To store the quiz form data on the database, you can use FormItSaveForm. This allows you to later view the data inside a Custom Manager Page (CMP) and export it, if need be.
Refer to the official docs for more usage examples: https://docs.modx.com/extras/revo/formit

How to select Radio button in Capybara with adjacent text?

The capybara choose method works well for a radio button which has the label tag next to it with the required text, like below:
<input id="rGEQr-real" type="radio" name="_pgcr6g7j"/>
<label id="rGEQr-cnt" class="z-radio-content" for="rGEQr-real">Web IDE Support</label>
page.choose('Web IDE Support') works fine for this.
But for something like this:
<form action="">
<input type="radio" value="male" name="sex"/>
MALE
<br/>
<input type="radio" value="female" name="sex"/>
FEMALE
</form>
which doesnt have label tag, the simple choose fails to set radio button.
How can we achieve this in Capybara??
If you need to choose a radio button by anything other than its name, id or label text, you will need to:
Find the radio button, typically with find and a CSS or XPath.
Call the set method
In this case, you will need to use XPath since CSS-selectors do not support locating by text. The XPath will need to check that the following sibling text node is the specified text. This can be done with:
# Select MALE
page.find(:xpath, '//input[following-sibling::text()[1][normalize-space(.) = "MALE"]]').set(true)
# Select FEMALE
page.find(:xpath, '//input[following-sibling::text()[1][normalize-space(.) = "FEMALE"]]').set(true)

Expression Engine if statement display new page

I wish to display a new page when the confirm status is met using expression engine. Please see code below:
<div class="column">
<p><button type="submit" class="submit" name="submit"><span>Submit Order</span></button> </p>
{if segment_2 == "confirm"}
{/exp:channel:Confirmation}
{/if}
</div>
If you have created a template that displays a confirmation message you can redirect to it inside a conditional:
{if segment_2 == "confirm"}
{redirect="template_group/template"}
{/if}
Though there might be a better way depending on what was used to create the form. Both Channel Form (Safecracker) and Freeform accept a return="" parameter that you can use to redirect people on submission.

How can I submit a form to a new tab in my chrome extension

I am working on a Google chrome extension. the idea is that I enter my username and password, click submit and have a new tab open with my website, which will then pick up the submitted form and log me in.
I have managed to open my website in a new tab, but can not get it to pick up the form.
You can use OnClick event in submit button:
<input type="submit" value="submit" onclick="this.form.target='_blank';return true;">
You can create an HTML form in your popup.html as follows:
<form name="input" action="http://example.com/login.php" method="get">
Username: <input type="text" name="user">
Password: <input type="password" name="password">
<input type="submit" value="Submit"></form>
And in the script of your website you can check if the parameters and have been passed, and if correct then create redirect them to the DashBoard on your site, otherwise show them the login page to enter the correct credentials
Since you've got your website loaded, try using jquery to select the textbox and enter a value.
The following selects the where the input is, then finds the input I want, then finally sets the value inside of that box.
$("td[data-key='sku']").find("input.tb-input").val('some text here')
In the jquery code above, the html would look something like this:
<td data-key='sku'>
<input class=tb-input/>
</td>

Resources